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 8915613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:00:39+00:00 2026-06-15T05:00:39+00:00

i want to create xml doc based on database record i have coded these

  • 0

i want to create xml doc based on database record i have coded these line but i don’t know how to put parent node in it:

$dom = new DOMDocument("1.0");
//header("Content-Type: text/plain");

while ($row = mysql_fetch_row($dtrs)) {
    //create sub toping..

    $root = $dom->createElement("case");
    $dom->appendChild($root);

    // create child element
    $caseno = $dom->createElement("caseno");
    $root->appendChild($caseno);

    // create text node
    $caseno_text = $dom->createTextNode($row[0]);
    $caseno->appendChild($caseno_text);


    // create child element
    $petname = $dom->createElement("petname");
    $root->appendChild($petname);

    // create text node
    $pet_text = $dom->createTextNode($row[1]);
    $petname->appendChild($pet_text);

    // create child element
    $resname = $dom->createElement("resname");
    $root->appendChild($resname);

    // create text node
    $res_text = $dom->createTextNode($row[2]);
    $resname->appendChild($res_text);

    // create child element
    $hearing = $dom->createElement("hearing");
    $root->appendChild($hearing);

    // create text node
    $hear_text = $dom->createTextNode($row[3]);
    $hearing->appendChild($hear_text);


    // create child element
    $status = $dom->createElement("status");
    $root->appendChild($status);

    // create text node
    $status_text = $dom->createTextNode($row[4]);
    $status->appendChild($status_text);
}

i get the Result like this where i am not able to put node in it

<?xml version="1.0"?> <case> <caseno>010301</caseno> <petname>ashiq</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case> <caseno>010302</caseno> <petname>hussain</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case>

actually i want my result like this;

<?xml version="1.0"?> <stage> <case> <caseno>010301</caseno> <petname>ashiq</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case> <caseno>010302</caseno> <petname>hussain</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case> </stage>

please help me out.

  • 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-15T05:00:41+00:00Added an answer on June 15, 2026 at 5:00 am

    You can’t have multiple root elements. You need to assign one root element outside the loop, and append you case elements to it:

    <?xml version="1.0"?>
    <cases>
        <case>
            <caseno>010301</caseno>
            <petname>ashiq</petname>
            <resname>state</resname>
            <hearing>8012-08-02</hearing>
            <status>P</status>
        </case>
        <case>
            <caseno>010302</caseno>
            <petname>hussain</petname>
            <resname>state</resname>
            <hearing>8012-08-02
            </hearing>
            <status>P</status>
        </case>
    </cases>
    

    Also, as an aside:

    Please, don’t use mysql_* functions in new code. They are no longer maintained and the deprecation process has begun on it. See the red box? Learn about prepared statements instead, and use PDO or MySQLi – this article will help you decide which. If you choose PDO, here is a good tutorial.

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

Sidebar

Related Questions

I want to create XML with dynamic Element and attribute according to Database record
I have an obeservable collection _kidlist and I want to create an XML doc
I have an XML file (on the left) and I want to create multiple
i want to save an .XML file that i create with php dom, but
I have a string which contains XML. I want to create an XMLdocument from
I want to create an xml file which have '&' in one of its
I want to parse a simple XML Doc and create simple syntax coloring... <parent>
So I have the following code, where I want to create a XML file
I want to create a XML file in csharp like the below format pls
i'm using the DOMdocument class in php whenever i want to create a XML

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.