Having read and used the NetronProject's "On tree diagrams and XML" that uses the Lithium Tree Layout control, I was motivated to include a class to handle imported XML. The class uses
XpathNavigator to work its way through the XML. It can also be used as an example for someone learning .NET classes as well.
The class first imports the XML, which needs to be valid, and then allows the user to specify, if the attributes are to be shown or not. If the attributes are to be shown then the user can specify that they be included in the node text or as child sub nodes. See the diagram above for the differing views.
ConsumeXml is the standalone class. Here are the steps required to use the class:
ConsumeXml LithiumHighway = new ConsumeXml(Xml);
LithiumHighway.AttributesShow = checkBoxAttributesOn.Checked;
LithiumHighway.AttributesAsChildren = checkBoxAttributesIncluded.Checked;
ColoringVisitor visitor = new ColoringVisitor();
catch (System.Exception ex)
MessageBox.Show("Exception Caught: " + ex.Message);
Here is the XML, that was used in the example which has a mix and match of attributes and data nodes:
<Child index='1'>Child data</Child>
<Other Show='f'>Other Data</Other>
<Final attr1='This' attr2='is' attr3='Radio' attr4='Clash'/>
ConsumeXml handles the traversal and other items and the display of nodes by trojan horsing the attribute(s) into the node. Thanks to a
System.Environment.NewLine inserted after the node text.
My goal was to quickly import XML, which seemed to be lacking in the primary project, for viewing of such data instead of editing it. So, after viewing, your mileage may vary. The test project needs to have the Lithium project included before it can compile correctly. So, install that project first and then add the Side Project as it is called in the Zip into Lithium's solution and then build.
After finding myself with lots of time after a cataclysmic event I have turned to doing programming to help fill the hours.