I’m still somewhat new to Visual Basic and XML so I don’t know if I’m phrasing this correctly. I have only scratched the surface of XSLT, but from what I’ve seen so far I don’t know if it can do this.
I am trying to recursively sort an XML file alphabetically by its tags in Visual Basic. For example, for an XML document, such as:
<catalog> <game> <title>Role-playing EXTREME Adventure</title> <platform>PC</platform> <type>Action/Adventure</type> <price>60.00</price> </game> <cd> <title>Music Notes</title> <artist>Susan Dylan</artist> <genre>Rock</genre> <company>Columbia</company> <year>1995</year> <price>10.95</price> </cd> <book> <title>Pictures of Things</title> <author>Bob Smith</author> <type>paper-back</type> <price>5.99</price> </book> </catalog>
…becomes:
<catalog> <book> <author>Bob Smith</author> <price>5.99</price> <title>Pictures of Things</title> <type>paper-back</type> </book> <cd> <artist>Susan Dylan</artist> <company>Columbia</company> <genre>Rock</genre> <price>10.95</price> <title>Music Notes</title> <year>1995</year> </cd> <game> <platform>PC</platform> <price>60.00</price> <title>Role-playing EXTREME Adventure</title> <type>Action/Adventure</type> </game> </catalog>
This sorted version should replace the contents of the XML file and be saved. This will be done for multiple, long XML files. I’m not at my work computer, so I don’t have access to the mess of Visual Basic code that I had been fiddling with. I’m beginning to think I should discard what I’ve done anyway though.
I apologize if this is answered somewhere. I spent most of the day searching and working on this. So if there is already an answer, I look forward to getting a link to it. 🙂
I saw this but it doesn’t seem to meet my needs. It must be done from within a Visual Basic and not a command line.
I appreciate any help.
Here’s a program you can use to sort XML (you’ll need at least .NET 3.0 to use LINQ to XML and extension methods, but this can also be accomplished with the old-style XML parsing libraries and regular methods):