Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,

i have a xml file like:

<a>
<1>Text1</1>
<2>Text2</2>
<3>Text3</3>
</a>

i have a two button up and down in aspx page. when i select a node element in dropdownlist and click on up button then node is going up:

like: i select a text3 in dropdownList and click up button. after it i want my xml file look like this:

<a>
<1>Text1</1>
<3>Text3</3>
<2>Text2</2>
</a>


please help me in this.

thanks in advance
Posted

I hope this will work.


XmlDocument xmlDocument = new XmlDocument();
 xmlDocument.PreserveWhitespace = false;
 xmlDocument.Load(@"file.xml");
 
XmlNode fieldNode = xmlDocument.SelectSingleNode(
 @"/root/field[@name = '3']");
 
if (fieldNode != null) {
 fieldNode.ParentNode.InsertBefore(fieldNode,
 fieldNode.PreviousSibling);
 }
 
// save changes somewhere
 // in this example simply the console to show changes
 xmlDocument.Save(Console.Out);
 
Share this answer
 
Comments
Member 8214635 30-Sep-11 2:04am    
is not working.. sorry
Come on, you don't need it anyway: "1", "2" and "3" are invalid tag names, so this is not even a well-formed XML, won't parse.

—SA
 
Share this answer
 
Comments
Member 8214635 30-Sep-11 1:15am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900