Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to know how to get a group of selected xml node and invert the nodes (not all nodes) just say a group of branches, reorder them from say branch node 10 to 1 , but leave their inner nodes alone ? Any ideas on where to begin , is there a short simple built in function for this ?
Posted
Updated 8-Apr-15 12:10pm
v2
Comments
Sergey Alexandrovich Kryukov 8-Apr-15 18:09pm    
Many ways. I wonder why, what would you like to achieve?
What have you tried so far?
—SA
stixoffire 9-Apr-15 12:06pm    
I have not tried anything as yet, I am looking at XML , and thinking to get the document, get the nodes of interest (via a tree or list view of selected nodes, and trying to make sure I am only getting those nodes in the tree that are of interest [selected] , get xml nodes as a collection that corresponds to the selection, allow the inversion of node sequence then rewrite the document (or should I simply get the xml and use a replace function). The reason for this is there is a program that exports in XML and based on the node position - sets the elements in the node sequence position .. so doing a simple inversion can take some time when doing this repetitively. Am I thinking about this the correct way or is there a better way to do it ? I do not need a bunch of code, I can write that myself - I just need some direction on the best way to go about it.
Maciej Los 9-Apr-15 13:22pm    
Based on what condition you want to reorder nodes in xml?
stixoffire 9-Apr-15 16:03pm    
The user selects the group of nodes. My code will invert the selection.

1 solution

.NET FCL provide more than enough techniques for working with XML. This is my short review of them:

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx.
  2. Use the classes System.Xml.XmlTextWriter and System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx, http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx.
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx, http://msdn.microsoft.com/en-us/library/bb387063.aspx.


Use whatever suite you most.

—SA
 
Share this answer
 
Comments
Maciej Los 9-Apr-15 13:15pm    
5ed!
Sergey Alexandrovich Kryukov 9-Apr-15 13:15pm    
Thank you, Maciej.
—SA
stixoffire 9-Apr-15 16:04pm    
Thank you Sergey!
Sergey Alexandrovich Kryukov 9-Apr-15 17:52pm    
You are very welcome.
Good luck, call again.
—SA

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