Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XML Reorder

XML Reorder

Scheduled Pinned Locked Moved C#
xmlhelpquestionannouncement
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H H is here

    Hello everyone, I would like to know if someone has experienced this problem: I have a xml file:

    <?xml version="1.0" standalone="yes"?>
    <requests>
    <request>
    <idRequest>123</idRequest>
    <requestType>001AA</requestType>
    <subRequest>
    <name>Some Name</name>
    <birthDate>12-12-2007</birthDate>
    <isbirthDateComplete>true</isbirthDateComplete>
    </subRequest>
    <observations>Some Observations...</observations>
    <recordType>Insert</recordType>
    </resquest>
    </requests>

    If I read the xml:

    DataSet dsTest = new DataSet();
    dsTeste.ReadXml(Application.StartupPath + "\\Test.xml");

    and then write it back:

    dsTest.WriteXml(Application.StartupPath + "\\Test1.xml");

    it gives me:

    <?xml version="1.0" standalone="yes"?>
    <requests>
    <request>
    <idRequest>123</idRequest>
    <requestType>001AA</requestType>
    <observations>Some Observations...</observations>
    <recordType>Insert</recordType>
    <subRequest>
    <name>Some Name</name>
    <birthDate>12-12-2007</birthDate>
    <isbirthDateComplete>true</isbirthDateComplete>
    </subRequest>
    </resquest>
    </requests>

    It simply change the order of the nodes. Is there any reason for this? Thanks in advance.

    L Offline
    L Offline
    led mike
    wrote on last edited by
    #2

    H@is@here wrote:

    Is there any reason for this?

    Yes and no. I'm pretty sure default Serialization does not guarantee order of nodes because in the XML standard order is not supported. Sorting is but not original order. Again, I'm not 100% sure but pretty confident.

    led mike

    H 1 Reply Last reply
    0
    • H H is here

      Hello everyone, I would like to know if someone has experienced this problem: I have a xml file:

      <?xml version="1.0" standalone="yes"?>
      <requests>
      <request>
      <idRequest>123</idRequest>
      <requestType>001AA</requestType>
      <subRequest>
      <name>Some Name</name>
      <birthDate>12-12-2007</birthDate>
      <isbirthDateComplete>true</isbirthDateComplete>
      </subRequest>
      <observations>Some Observations...</observations>
      <recordType>Insert</recordType>
      </resquest>
      </requests>

      If I read the xml:

      DataSet dsTest = new DataSet();
      dsTeste.ReadXml(Application.StartupPath + "\\Test.xml");

      and then write it back:

      dsTest.WriteXml(Application.StartupPath + "\\Test1.xml");

      it gives me:

      <?xml version="1.0" standalone="yes"?>
      <requests>
      <request>
      <idRequest>123</idRequest>
      <requestType>001AA</requestType>
      <observations>Some Observations...</observations>
      <recordType>Insert</recordType>
      <subRequest>
      <name>Some Name</name>
      <birthDate>12-12-2007</birthDate>
      <isbirthDateComplete>true</isbirthDateComplete>
      </subRequest>
      </resquest>
      </requests>

      It simply change the order of the nodes. Is there any reason for this? Thanks in advance.

      M Offline
      M Offline
      Mbah Dhaim
      wrote on last edited by
      #3

      because the dataset you create based on that xml will order xml contents as 2 datatable, 'request' and 'subrequest' where those datatable have hidden relation try dsTest.WriteXmlSchema(filename) to know its structure

      dhaim program is hobby that make some money as side effect :)

      H 1 Reply Last reply
      0
      • L led mike

        H@is@here wrote:

        Is there any reason for this?

        Yes and no. I'm pretty sure default Serialization does not guarantee order of nodes because in the XML standard order is not supported. Sorting is but not original order. Again, I'm not 100% sure but pretty confident.

        led mike

        H Offline
        H Offline
        H is here
        wrote on last edited by
        #4

        Hello and thank you for your answer. And what is more interesting is that I have a xsd file with this xml and it still reorder the xml. X| Humm!

        1 Reply Last reply
        0
        • M Mbah Dhaim

          because the dataset you create based on that xml will order xml contents as 2 datatable, 'request' and 'subrequest' where those datatable have hidden relation try dsTest.WriteXmlSchema(filename) to know its structure

          dhaim program is hobby that make some money as side effect :)

          H Offline
          H Offline
          H is here
          wrote on last edited by
          #5

          Hi again, Yes i know that. Even if you use the XmlWriteMode.WriteSchema with the xml, edit the schema with VS to match the order, read the edited file and save it again the result is the same. It simply doesn't maintain the order. Thanks ans best regards

          1 Reply Last reply
          0
          • H H is here

            Hello everyone, I would like to know if someone has experienced this problem: I have a xml file:

            <?xml version="1.0" standalone="yes"?>
            <requests>
            <request>
            <idRequest>123</idRequest>
            <requestType>001AA</requestType>
            <subRequest>
            <name>Some Name</name>
            <birthDate>12-12-2007</birthDate>
            <isbirthDateComplete>true</isbirthDateComplete>
            </subRequest>
            <observations>Some Observations...</observations>
            <recordType>Insert</recordType>
            </resquest>
            </requests>

            If I read the xml:

            DataSet dsTest = new DataSet();
            dsTeste.ReadXml(Application.StartupPath + "\\Test.xml");

            and then write it back:

            dsTest.WriteXml(Application.StartupPath + "\\Test1.xml");

            it gives me:

            <?xml version="1.0" standalone="yes"?>
            <requests>
            <request>
            <idRequest>123</idRequest>
            <requestType>001AA</requestType>
            <observations>Some Observations...</observations>
            <recordType>Insert</recordType>
            <subRequest>
            <name>Some Name</name>
            <birthDate>12-12-2007</birthDate>
            <isbirthDateComplete>true</isbirthDateComplete>
            </subRequest>
            </resquest>
            </requests>

            It simply change the order of the nodes. Is there any reason for this? Thanks in advance.

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #6

            The better question is...does it really matter? XML wasn't designed for and isn't intended to be human-readable; it was designed to provide a consistent structure for data. The fact that you have a schema doesn't define the order of elements other than to indicate what elements are valid subelements of another element. As long as the XML structure matches the structure defined in the schema everything is happy. The fact that an element is listed first or third doesn't matter. As to the reason it is reordering, there are several possibilities. The most likely one is that the XmlSerializer doesn't guarantee order. It is going to write out the XML in the order defined by the Datatable/Dataset.

            Scott Dorman

            Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


            Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

            L H 2 Replies Last reply
            0
            • S Scott Dorman

              The better question is...does it really matter? XML wasn't designed for and isn't intended to be human-readable; it was designed to provide a consistent structure for data. The fact that you have a schema doesn't define the order of elements other than to indicate what elements are valid subelements of another element. As long as the XML structure matches the structure defined in the schema everything is happy. The fact that an element is listed first or third doesn't matter. As to the reason it is reordering, there are several possibilities. The most likely one is that the XmlSerializer doesn't guarantee order. It is going to write out the XML in the order defined by the Datatable/Dataset.

              Scott Dorman

              Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


              Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #7

              So what I said ;P

              led mike wrote:

              because in the XML standard order is not supported. Sorting is but not original order.

              led mike

              1 Reply Last reply
              0
              • S Scott Dorman

                The better question is...does it really matter? XML wasn't designed for and isn't intended to be human-readable; it was designed to provide a consistent structure for data. The fact that you have a schema doesn't define the order of elements other than to indicate what elements are valid subelements of another element. As long as the XML structure matches the structure defined in the schema everything is happy. The fact that an element is listed first or third doesn't matter. As to the reason it is reordering, there are several possibilities. The most likely one is that the XmlSerializer doesn't guarantee order. It is going to write out the XML in the order defined by the Datatable/Dataset.

                Scott Dorman

                Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                H Offline
                H Offline
                H is here
                wrote on last edited by
                #8

                Hi and thank you for your answer. Yes, your are right, for me it doesn't matter. It is mattering for the other system that am communicating with. I was only trying to check if there was a reason for that or if I could do something about it. Best regards for all. :)

                M S 2 Replies Last reply
                0
                • H H is here

                  Hi and thank you for your answer. Yes, your are right, for me it doesn't matter. It is mattering for the other system that am communicating with. I was only trying to check if there was a reason for that or if I could do something about it. Best regards for all. :)

                  M Offline
                  M Offline
                  Mbah Dhaim
                  wrote on last edited by
                  #9

                  so you have to write your xml output manually :-\

                  dhaim program is hobby that make some money as side effect :)

                  1 Reply Last reply
                  0
                  • H H is here

                    Hi and thank you for your answer. Yes, your are right, for me it doesn't matter. It is mattering for the other system that am communicating with. I was only trying to check if there was a reason for that or if I could do something about it. Best regards for all. :)

                    S Offline
                    S Offline
                    Scott Dorman
                    wrote on last edited by
                    #10

                    H@is@here wrote:

                    It is mattering for the other system that am communicating with.

                    Not to sound flippant, but it shouldn't matter to the other system as well. The fact that it does probably means that they aren't using an XML parser to read the XML and are doing all of the parsing by hand. This is wrong on so many different levels. They should rethink how they are doing the XML parsing and use an actual parser so they don't have that problem.

                    Scott Dorman

                    Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                    Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                    H 1 Reply Last reply
                    0
                    • S Scott Dorman

                      H@is@here wrote:

                      It is mattering for the other system that am communicating with.

                      Not to sound flippant, but it shouldn't matter to the other system as well. The fact that it does probably means that they aren't using an XML parser to read the XML and are doing all of the parsing by hand. This is wrong on so many different levels. They should rethink how they are doing the XML parsing and use an actual parser so they don't have that problem.

                      Scott Dorman

                      Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                      Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                      H Offline
                      H Offline
                      H is here
                      wrote on last edited by
                      #11

                      Scott Dorman wrote:

                      Not to sound flippant

                      Not at all, it is a old system, and probably they are processing the xml manually. X| Thanks again.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups