View Single Post
Old 03-25-2017, 10:31 AM  
k33n
Confirmed User
 
Join Date: Feb 2009
Posts: 201
Thank you for the code,it is working great with test.xml but the original file has more elements than the test example:
Code:
<?xml version="1.0" encoding="utf-8"?>
<root>
  <element>
    <username>Username A</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	<child1>this is child 1</child1>
	<child2>this is child 2</child2>
	<child3>this is child 3</child3>
      </another>
    </about>
    <persons>
      <person>
      <gender>female</gender>
      <age>29</age>
      <status>single</status>
      <body>
	<build>petite</build>
	<hairLength>shoulder length</hairLength>
	<hairColor>brown</hairColor>
	<eyeColor>green</eyeColor>
     </body>
     <decorations>
	<decoration>tatoo</decoration>
	<decoration>tongue piercing</decoration>
	<decoration>belly button</decoration>
     </decorations>
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username B</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	<child1>this is child 1</child1>
	<child2>this is child 2</child2>
	<child3>this is child 3</child3>
      </another>
    </about>
    <persons>
      <person>
      <gender>female</gender>
      <age>35</age>
      <status>single</status>
      <body>
	<build>petite</build>
	<hairLength>shoulder length</hairLength>
	<hairColor>brown</hairColor>
	<eyeColor>green</eyeColor>
     </body>
     <decorations>
	<decoration>tatoo</decoration>
	<decoration>tongue piercing</decoration>
	<decoration>belly button</decoration>
     </decorations>
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username C</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	<child1>this is child 1</child1>
	<child2>this is child 2</child2>
	<child3>this is child 3</child3>
      </another>
    </about>
    <persons>
      <person>
      <gender>female</gender>
      <age>35</age>
      <status>single</status>
      <body>
	<build>petite</build>
	<hairLength>shoulder length</hairLength>
	<hairColor>brown</hairColor>
	<eyeColor>green</eyeColor>
     </body>
     <decorations>
	<decoration>tatoo</decoration>
	<decoration>tongue piercing</decoration>
	<decoration>belly button</decoration>
     </decorations>
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username D</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	<child1>this is child 1</child1>
	<child2>this is child 2</child2>
	<child3>this is child 3</child3>
      </another>
    </about>
    <persons>
      <person>
      <gender>female</gender>
      <age>22</age>
      <status>single</status>
      <body>
	<build>petite</build>
	<hairLength>shoulder length</hairLength>
	<hairColor>brown</hairColor>
	<eyeColor>green</eyeColor>
     </body>
     <decorations>
	<decoration>tatoo</decoration>
	<decoration>tongue piercing</decoration>
	<decoration>belly button</decoration>
     </decorations>
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username E</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	<child1>this is child 1</child1>
	<child2>this is child 2</child2>
	<child3>this is child 3</child3>
      </another>
    </about>
    <persons>
      <person>
      <gender>female</gender>
      <age>31</age>
      <status>single</status>
      <body>
	<build>petite</build>
	<hairLength>shoulder length</hairLength>
	<hairColor>brown</hairColor>
	<eyeColor>green</eyeColor>
     </body>
     <decorations>
	<decoration>tatoo</decoration>
	<decoration>tongue piercing</decoration>
	<decoration>belly button</decoration>
     </decorations>
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
</root>
The result is a sorted file but with missing elements:
Code:
<?xml version="1.0" encoding="utf-8"?>
<root>
  <element>
    <username>Username E</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	
	
	
      </another>
    </about>
    <persons>
      <person>
      
      
      
      
     
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username D</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	
	
	
      </another>
    </about>
    <persons>
      <person>
      
      
      
      
     
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username C</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	
	
	
      </another>
    </about>
    <persons>
      <person>
      
      
      
      
     
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username B</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	
	
	
      </another>
    </about>
    <persons>
      <person>
      
      
      
      
     
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
  <element>
    <username>Username A</username>
    <about>
      <description>random description</description>
      <from>A place on earth</from>
      <since>1999</since>
      <another>
	
	
	
      </another>
    </about>
    <persons>
      <person>
      
      
      
      
     
     </person>
    </persons>
    <profileImage>url to jpg</profileImage>
  </element>
</root>
I tried to adapt the code but with no result. Can you please give me a solution? Thank you!
Quote:
Originally Posted by TitanWM View Post
Why not sort the output? Have you by the assorted xml a performance advantage?
I believe so.Maybe i am talking nonsense but if i sort the output,would be done every time the page loads.Instead i am sorting the xml file and save it for future use.
k33n is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote