Jump to content
  • Advertisement
Sign in to follow this  

XML and Trees

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[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
Forgot to mention some of the namespaces/objects I am referring to here:

--> XmlDocument
--> XmlNode
--> XmlReader
--> XmlWriter

--> XmlSchema
--> XmlSchemaDocumentation

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!