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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:33:32+00:00 2026-06-06T04:33:32+00:00

I have an XML string as follows: <?xml version=1.0 encoding=utf-8?> <document id=0 name=RegSimple Version=0.1>

  • 0

I have an XML string as follows:

<?xml version="1.0" encoding="utf-8"?>
<document id="0" name="RegSimple" Version="0.1">
<Description>
    Configuration document for simple registration of incidents.
    This document will contain both the fixed and the user-defined fields to
    show on the registration screen.
</Description>
<Fields>
    <Textbox id="1" name="IncidentID" visibility="Hidden" width="500"
        displayreadonly="False" />
    <Comment id="200" height="10" name="c1" caption=" " />
    <Header id="100" name="Header" caption="Description" />
    <Radiobox id="2" name="Type" caption="Feedback type" width="500"
        type="19" displayreadonly="true"></Radiobox>
    <Textbox id="3" name="Description" caption="My feedback"
        width="500" height="75" multiline="True" required="True"
        displayreadonly="True" />
    <Textbox id="4" name="Incident" caption="Title *" width="500"
        height="25" multiline="False" required="True" displayreadonly="False" />
    <Comment id="201" width="500" name="Comment2"
        caption="* All messages are published with a short title that describes the feedback"
        multiline="True" height="40" />
    <Comment id="202" height="20" name="c1" caption=" " />
    <Combobox id="5" name="Unit" caption="Unit" width="500" type="12"
        required="True" displayreadonly="True"></Combobox>
    <Combobox id="6" name="Country" caption="Country" width="500"
        type="11" required="True" displayreadonly="True"></Combobox>
    <Textbox id="7" name="Office" caption="Office" height="50"
        width="500" multiline="True" displayreadonly="True" />
    <Textbox id="8" name="Cause" caption="Cause" height="50"
        width="500" multiline="True" displayreadonly="True" />
    <Textbox id="9" name="Action" caption="Recommended actions"
        height="50" width="500" multiline="True" displayreadonly="True" />
    <Combobox id="10" name="Theme" caption="Theme" width="500"
        type="3" required="True" displayreadonly="True"></Combobox>
    <Header id="102" name="Time" caption="Date, Time and location" />
    <Datetime id="11" name="Date" caption="Date" width="120"
        displayreadonly="True" />
    <Textbox id="12" name="Time" caption="Time" width="120"
        displayreadonly="True" property="True" />
    <Textbox id="13" name="Location" caption="Location" width="500"
        displayreadonly="True" />
    <Header id="103" name="info" caption="Contact information" />
    <Textbox id="14" name="Name" caption="Name" width="500" tag="user.name"
        displayreadonly="False" />
    <Textbox id="15" name="E-Mail" caption="E-Mail" width="500"
        tag="user.e-mail" displayreadonly="False" />
    <Textbox id="16" name="Registered date" visibility="Hidden"
        width="500" tag="system.date" displayreadonly="False" />
</Fields>
</document>

I want the elements in the XML to be parsed sequentially i.e in the order they appear in the original string. But using SimpleXMLElement and simplexml_load_string give arrays of similar elements as following:

object(SimpleXMLElement)[292]
  public '@attributes' => 
    array
      'id' => string '0' (length=1)
      'name' => string 'RegSimple' (length=9)
      'Version' => string '0.1' (length=3)
  public 'Description' => string '
    Configuration document for simple registration of incidents.
    This document will contain both the fixed and the user-defined fields to show on the registration screen.
  ' (length=178)
  public 'Fields' => 
    object(SimpleXMLElement)[293]
      public 'Textbox' => 
        array
          0 => 
            object(SimpleXMLElement)[294]
              public '@attributes' => 
                array
                  'id' => string '1' (length=1)
                  'name' => string 'IncidentID' (length=10)
                  'visibility' => string 'Hidden' (length=6)
                  'width' => string '500' (length=3)
                  'displayreadonly' => string 'False' (length=5)
          1 => 
            object(SimpleXMLElement)[298]
              public '@attributes' => 
                array
                  'id' => string '3' (length=1)
                  'name' => string 'Description' (length=11)
                  'caption' => string 'My feedback' (length=11)
                  'width' => string '500' (length=3)
                  'height' => string '75' (length=2)
                  'multiline' => string 'True' (length=4)
                  'required' => string 'True' (length=4)
                  'displayreadonly' => string 'True' (length=4)
          2 => 
            object(SimpleXMLElement)[299]
              public '@attributes' => 
                array
                  'id' => string '4' (length=1)
                  'name' => string 'Incident' (length=8)
                  'caption' => string 'Title *' (length=7)
                  'width' => string '500' (length=3)
                  'height' => string '25' (length=2)
                  'multiline' => string 'False' (length=5)
                  'required' => string 'True' (length=4)
                  'displayreadonly' => string 'False' (length=5)
      public 'Comment' => 
        array
          0 => 
            object(SimpleXMLElement)[295]
              public '@attributes' => 
                array
                  'id' => string '200' (length=3)
                  'height' => string '10' (length=2)
                  'name' => string 'c1' (length=2)
                  'caption' => string ' ' (length=1)
          1 => 
            object(SimpleXMLElement)[300]
              public '@attributes' => 
                array
                  'id' => string '201' (length=3)
                  'width' => string '500' (length=3)
                  'name' => string 'Comment2' (length=8)
                  'caption' => string '* All messages are published with a short title that describes the feedback' (length=75)
                  'multiline' => string 'True' (length=4)
                  'height' => string '40' (length=2)
          2 => 
            object(SimpleXMLElement)[301]
              public '@attributes' => 
                array
                  'id' => string '202' (length=3)
                  'height' => string '20' (length=2)
                  'name' => string 'c1' (length=2)
                  'caption' => string ' ' (length=1)
      public 'Header' => 
        array
          0 => 
            object(SimpleXMLElement)[296]
              public '@attributes' => 
                array
                  'id' => string '100' (length=3)
                  'name' => string 'Header' (length=6)
                  'caption' => string 'Description' (length=11)
          1 => 
            object(SimpleXMLElement)[308]
              public '@attributes' => 
                array
                  'id' => string '102' (length=3)
                  'name' => string 'Time' (length=4)
                  'caption' => string 'Date, Time and location' (length=23)
          2 => 
            object(SimpleXMLElement)[312]
              public '@attributes' => 
                array
                  'id' => string '103' (length=3)
                  'name' => string 'info' (length=4)
                  'caption' => string 'Contact information' (length=19)
      public 'Radiobox' => 
        object(SimpleXMLElement)[297]
          public '@attributes' => 
            array
              'id' => string '2' (length=1)
              'name' => string 'Type' (length=4)
              'caption' => string 'Feedback type' (length=13)
              'width' => string '500' (length=3)
              'type' => string '19' (length=2)
              'displayreadonly' => string 'true' (length=4)
      public 'Combobox' => 
        array
          0 => 
            object(SimpleXMLElement)[302]
              public '@attributes' => 
                array
                  'id' => string '5' (length=1)
                  'name' => string 'Unit' (length=4)
                  'caption' => string 'Unit' (length=4)
                  'width' => string '500' (length=3)
                  'type' => string '12' (length=2)
                  'required' => string 'True' (length=4)
                  'displayreadonly' => string 'True' (length=4)
          1 => 
            object(SimpleXMLElement)[303]
              public '@attributes' => 
                array
                  'id' => string '6' (length=1)
                  'name' => string 'Country' (length=7)
                  'caption' => string 'Country' (length=7)
                  'width' => string '500' (length=3)
                  'type' => string '11' (length=2)
                  'required' => string 'True' (length=4)
                  'displayreadonly' => string 'True' (length=4)

In this result all the Textbox elements are returned in a single array. Similarly all comments and Comboboxes are returned in separate arrays irrespective of there order in the original XML.

Can anyone tell me how to parse the elements in their actual order?
Thanks.

  • 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-06T04:33:33+00:00Added an answer on June 6, 2026 at 4:33 am

    You can use SimpleXmlIterator and RecursiveIteratorIterator to traverse the tree:

    $tree = new RecursiveIteratorIterator(
        new SimpleXmlIterator($xml),
        RecursiveIteratorIterator::SELF_FIRST
    );
    
    foreach ($tree as $node) {
        echo $node->getName(), PHP_EOL;
    }
    

    will output (demo)

    Description
    Fields
    Textbox
    Comment
    Header
    Radiobox
    Textbox
    Textbox
    Comment
    Comment
    Combobox
    Combobox
    Textbox
    Textbox
    Textbox
    Combobox
    Header
    Datetime
    Textbox
    Textbox
    Header
    Textbox
    Textbox
    Textbox
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a XML file as follows: <?xml version=1.0 encoding=utf-8 ?> <publisher> <name>abc</name> <link>http://</link>
I have an Xml document: <?xml version=1.0 encoding=utf-8?> <Family xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Person member=father id=0>
Given the intitial XML (BPEL) file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema>
I have a bean mongoService which looks like as <?xml version=1.0 encoding=UTF-8?> <beans xmlns=http://www.springframework.org/schema/beans
I have a XML code like this: <?xml version=1.0 encoding=utf-8 ?> <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml>
I have a widget layout as follow : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/widget
I have some XML in a unicode-string variable in Python as follows: <?xml version='1.0'
I have a task of parsing a simple XML-formatted string in a MySQL stored
I have a string containing XML document using LinqtoXML What is the best way
He is my XML hosted on remote machine: <?xml version=1.0 encoding=UTF-8?> <store xmlns=http://mydomain.com/store/schemas> <!--

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.