Sign in to follow this  
plywood

XML and Trees

Recommended Posts

plywood    103
[Visual Studio .NET, C#] I am aware that Visual Studio has an interesting feature that reads an "undefined" (no XSD provided) XML file and *infer* its schema, thereby automating the XSD creation. So long as your XML file is consistent and well-formed, its about 99% accurate, and just requires moderate tweaking to get your XSD right. I have a *lot* of data stored inside my XML file, which I believe to well-formed. My intention is to use this automated feature to generate (and then subsequently, tweak) my XML lang's XSD. My original plan, before really thinking things through, was to read the actual .xml file into an XmlDocument object, and then convert this document into a tree data structure, representing my xml nodes as actual nodes of a generic tree. Observe:
public class Node<>; // Generic Node
public class Tree<>; // Generic Tree

// So...
Tree<int> intTree = new Tree<int>();
Tree<Dog> dogTree = new Tree<Dog>();

Tree<Widget> widgetTree = ConvertXMLToTree("myfile.xml");

My app would then directly process and manipulate the tree object. But this got me thinking, is there a way for me to use System.Xml to manipulate the internal tree (since XML is a tree, I assume the System object uses a tree as well) the same way as I would with my own proprietary tree, thereby saving me the effort of writing the ConvertXMLToTree() and ConvertTreeToXML methods? In order to achieve what my app requires, I would need System.Xml (any of the five major namespaces) to perform the following typical tree operations, either through XPath or other: (i) Exhibit the behavior of what I call "multi-trees," that is, trees with 0+ branches at any level. A parent could have 3 children, with the 1st child being a leaf, the 2nd child having 50 children, and the 3rd child have 3 children itself... (ii) Access and Modify nodes anywhere in the tree; getting, setting, adding, deleting nodes anywhere I want to (iii) Advanced operations, such as swapping major branches with each other, etc. (iv) Traversing the tree, in any order I specify (post, in, pre or other). So what this is all boiling down to are 2 simple questions: (1) Can the XML API in .NET accomplish all these goals (above) and more? (2) If not, is there a generic Tree structure somewhere in the framework so that I don't have to write my own Tree? For example, there is LinkedList and HashTable. If so, what is the name of this Tree and what namespace is it in?

Share this post


Link to post
Share on other sites
plywood    103
Forgot to mention some of the namespaces/objects I am referring to here:


System.Xml
--> XmlDocument
--> XmlNode
--> XmlReader
--> XmlWriter

System.Xml.Schema
--> XmlSchema
--> XmlSchemaDocumentation

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this