Jump to content

Tree Data structure ---> DOM or XML or whatever it fits


Luxuguy

Recommended Posts

Hi all,First of all I'd like to give a little info about myself: I'm not a CS major and I've just gotten into XML and DOM a few days ago (due to a new job assignment).Here is the problem I have: I have a Tree data structure, can be very simple like this:Class Node{ string NodeName;}Class Tree{ Node root; ArrayList<Node> Children; // Well, it can have more than 1 children. .... // blah blah blah, a couple of methods here}I've successfully created a tree like this:------------------------------------------------------------------------SERIES -------> PARALLEL -------> "A"............|.........................|------> "B"............|.........................|------> "C"............|............|------> "D"............|------> "E"(Please Ignore the dots ".". The browser wouldn't display spaces correctly.)( Simply saying: there is a root "SERIES". It has 3 child: "PARALLEL", "D", "E". Child "PARALLEL" has 3 other children "A", "B", "C". )------------------------------------------------------------------------Here is what I want: Convert this tree to a "structure" like this, DOM or XML???, or whatever it is (I'm not very good at these terminology):---------------------------------------------------------------------------<?xml version="1.0" encoding="ISO-8859-1"?><Rung> <RungElement data="SERIES"> <RungElement data="PARALLEL"> <RungElement data="A"> </RungElement> <RungElement data="B"> </RungElement> <RungElement data="C"> </RungElement> </RungElement> </RungElement> <RungElement data="D"> </RungElement> <RungElement data="E"> </RungElement></Rung>---------------------------------------------------------------------------I'm using .NET 2.0 (required at work, but if there is no other option, 3.0 is ok I guess).I guess my question is how I convert from the Tree ---> text (structure) above ?Any idea and suggestion are appreciated.Many thanks in advance,Luxuguy

Link to comment
Share on other sites

I don't really know how to do that in C#, but you could read upon DOM and try to find out how it is used in C#.DOM (Document Object Model) is the representation of XML (text). You use the DOM classes to create a DOM structure which is then translated to XML text with the save() or saveXML() methods of the "document" object (named differently in various implementations, most often something like "DOMDocument").I guess your question is truly how to use DOM in C#, but the only thing I could find was this, which is not really DOM, but rather a WMP extension to it for playlist creation's sake. Still, it may be a good place to start.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...