.net - Order xml file using linq2xml -


following question filter xml linq2xml

after succesfully filtering (removing nodes) xml file. i'd order attribute in nodes.

sample of xml file:

<root>     <group price="50">         <item price="60"/>         <item price="50"/>         <item price="70"/>     </group>     <group price="55">         <item price="62"/>         <item price="57"/>         <item price="55"/>     </group>     <group price="61">         <item price="62"/>         <item price="61"/>         <item price="65"/>      </group>      <!--more group nodes-->   </root>  

and i'd get:

<root>     <group price="61">         <item price="65"/>         <item price="62"/>         <item price="61"/>      </group>      <group price="55">         <item price="62"/>         <item price="57"/>         <item price="55"/>     </group>     <group price="50">         <item price="70"/>         <item price="60"/>         <item price="50"/>     </group>     <!--more group nodes-->   </root> 

my current code (mix linq2xml , xpath):

'first remove group nodes prices higher 60 (and sons).  dim filter string="./root/group[not(translate(@price, ',.', '.')<=60})]"  elements = doc.xpathselectelements(filter).orderbydescending((function(x) ctype(x.attribute("price"), decimal)))  'remove elements don't fullfill condition  (prices higher 60)                    elements.remove()  'after remove item nodes prices higher 60  filter string="./root/group/item[not(translate(@price, ',.', '.')<=60})]"  elements = doc.xpathselectelements(filter).orderbydescending((function(x) ctype(x.attribute("price"), decimal)))  'remove elements don't fullfill condition  (prices higher 60)  elements.remove() 

as said before, i'm filtering succesfully i'm not able order (descending in case). there way order group nodes , item nodes in 1 step or have in 2 steps?

someone told me using replacenodes of xdocument don't results.

thanks again replies.

if want order group descending can use linq , orderbydescending.

xdocument doc = xdocument.parse("<root>  <group price=\"50\">  <item price=\"60\"/>  <item    price=\"50\"/>  <item price=\"70\"/>  </group>  <group price=\"55\">  <item price=\"62\"/>  <item price=\"57\"/>  <item price=\"55\"/>  </group>  <group price=\"61\">  <item price=\"62\"/>  <item price=\"61\"/> <item price=\"65\"/>  </group>  <!--more group nodes-->   </root>  ");  ienumerable<xelement> list = doc.elements()                                 .elements("group")                                 .orderbydescending(p => convert.toint32(p.attribute("price").value)); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -