Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:07:48+00:00 2026-06-15T10:07:48+00:00

I have a php function inside one of my classes that simply creates an

  • 0

I have a php function inside one of my classes that simply creates an XML file of all of the objects. This is the code:

function writeXML(){
        //LOAD PROFILE
        //print "Profiles: <br>";
        //$pro = new Profile();

        $profileArray = $this->getAll();

        //var_dump($profileArray);
        //CHECK TO SEE IF THE XML FILE EXISTS IN THE LIBRARY/CONFIGURATION
        if(file_exists($_SESSION['ini'][rootPath] . "v/p.xml")){
            unlink($_SESSION['ini'][rootPath] . "v/p.xml");
        }

        //CREATE XML FILE
        //CREATE ROOT NODE
        $doc = new DOMDocument("1.0");
        $doc->formatOutput = true;

        //CREATE ROOT NODE
        print "Creating nodes";
        $root = $doc->createElement("profiles");
        $root = $doc->appendChild($root);

        //ADD NODES
        //print "<br>Creating children";
        foreach($profileArray as $member){
                    //AS WE CYCLE THROUGH THE ARRAY GET THE ARRAY OF OBJECT PARAMETERS
                    $memberArray = $member->toArray();

                    //var_dump($memberArray);

            //CREATE MEMBER NODE TO ROOT
            $person = $doc->createElement("profile");
            $person = $root->appendChild($person);

            //CREATE CHILD NODES FOR MEMBER
                        /*
                         * ID IS NOT NEEDED FOR IOS APP
            $id = $doc->createElement("ID");
            $id = $person->appendChild($id);

            $idValue = $doc->createTextNode($member->get_id());
            $idValue = $id->appendChild($idValue);
            */


            $lastName = $doc->createElement("lastName");
            $lastName = $person->appendChild($lastName);

            //$lastNameValue = $doc->createTextNode($member->get_lname());
                        $lastNameValue = $doc->createTextNode($memberArray['lastName']);
            $lastNameValue = $lastName->appendChild($lastNameValue);

            $firstName = $doc->createElement("firstName");
            $firstName = $person->appendChild($firstName);

            $firstNameValue = $doc->createTextNode($memberArray['firstName']);
                        //$firstNameValue = $doc->createTextNode($member->get_fname());
            $firstNameValue = $firstName->appendChild($firstNameValue);

                        $mobile = $doc->createElement("mobile");
            $mobile = $person->appendChild($mobile);

                        $mobileValue = $doc->createTextNode($memberArray['mobile']);
                        //$mobileValue = $doc->createTextNode($member->get_mobile());
            $mobileValue = $mobile->appendChild($mobileValue);

                        $phone = $doc->createElement("phone");
            $phone = $person->appendChild($phone);

            $phoneValue = $doc->createTextNode($memberArray['phone']);
                        //$phoneValue = $doc->createTextNode($member->get_phone());
            $phoneValue = $phone->appendChild($phoneValue);

            $email = $doc->createElement("email");
            $email = $person->appendChild($email);

            $emailValue = $doc->createTextNode($memberArray['email']);
                        //$emailValue = $doc->createTextNode($member->get_email());
            $emailValue = $email->appendChild($emailValue);

            $altEmail = $doc->createElement("altEmail");
            $altEmail = $person->appendChild($altEmail);

            $altEmailValue = $doc->createTextNode($memberArray['altEmail']);
                        //$altEmailValue = $doc->createTextNode($member->get_altemail());
            $altEmailValue = $altEmail->appendChild($altEmailValue);

            $street = $doc->createElement("address");
            $street = $person->appendChild($street);

            $streetValue = $doc->createTextNode($memberArray['street']);
                        //$streetValue = $doc->createTextNode($member->get_street());
            $streetValue = $street->appendChild($streetValue);

            $city = $doc->createElement("city");
            $city = $person->appendChild($city);

            $cityValue = $doc->createTextNode($memberArray['city']);
                        //$cityValue = $doc->createTextNode($member->get_city());
            $cityValue = $city->appendChild($cityValue);

            $state = $doc->createElement("state");
            $state = $person->appendChild($state);

            $stateValue = $doc->createTextNode($memberArray['state']);
                        //$stateValue = $doc->createTextNode($member->get_state());
            $stateValue = $state->appendChild($stateValue);

            $zip = $doc->createElement("zip");
            $zip = $person->appendChild($zip);

            $zipValue = $doc->createTextNode($memberArray['zip']);
                        //$zipValue = $doc->createTextNode($member->get_zip());
            $zipValue = $zip->appendChild($zipValue);

                        $image = $doc->createElement("image");
                        $image = $person->appendChild($image);

                        $imageValue = $doc->createTextNode($memberArray['image']);
                        $imageValue = $image->appendChild($imageValue);

            $titles = $doc->createElement("title");
            $titles = $person->appendChild($titles);

                        $titlesValue = $doc->createTextNode($memberArray['title']);
            //$titlesValue = $doc->createTextNode($member->get_field5());
            $titlesvalue = $titles->appendChild($titlesValue);

                        $group = $doc->createElement("group");
                        $group = $person->appendChild($group);

                        $groupValue = $doc->createTextNode($memberArray['group']);
                        $groupVAlue = $person->appendChild($groupValue);
        }
        print "<br>Saving XML<br><br>";
        $xml_string = $doc->saveXML();
        print "XML<br>";
        print $xml_string;
                print "<br>";
                print "Path: " . $_SESSION['ini']['rootPath'] . "public_html/v/p.xml";

        //if($doc->save($_SESSION['ini']['htmlPath'] . "v/p.xml")) return true;
                //else return false;
                print "Bytes: " . $doc->save($_SESSION['ini']['rootPath'] . "public_html/v/p.xml");

    }

I really need another set of eyes on this as the saveXML completes and even spits out the $xml_string to the screen. However, the $doc->save does not show anything at all.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:07:51+00:00Added an answer on June 15, 2026 at 10:07 am

    If you want to save the xml to a file you need to use save, not saveXML.

    Do you pass the filename to the save? the save will be like:

    $filename=$_SESSION['ini'][rootPath] . "v/p.xml";
    $doc->save($filename);
    

    Other question: $_SESSION['ini'][rootPath] are you sure if it’s setted?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that creates the navigation for a slideshow. It works just
I have two classes, one of them is a configuration class. Inside of this
I have a php that echos html. Inside one of these echos I have
I have a PHP function that extract dat of an invoice from DB. The
I have a PHP function that builds a JSON array via $jsonArray= array(); for
I have a PHP function that takes a variable number of arguments (using func_num_args()
I have a PHP function that requires can take 3 parameteres... I want to
I have a PHP function that I want to make available publically on the
Is it possible to have a PHP function that is both recursive and anonymous?
I have a $.post function inside of a loop. All it does it call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.