Click here to Skip to main content
Click here to Skip to main content
Go to top

Add-on class to process XML using XPathNavigator into Lithium Tree Control

, 15 Apr 2005
Rate this:
Please Sign up or sign in to vote.
This class will take any valid XML and parse out the nodes with or without the attributes into a Lithium Tree Layout control for viewing.

Introduction

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:

try
{
  // Step 1 Load Xml
  ConsumeXml LithiumHighway = new ConsumeXml(Xml);
  // Step 2 Turn on or off attributes.                
  LithiumHighway.AttributesShow = checkBoxAttributesOn.Checked;
  // Step 3 Specify attributes as child nodes or within the node text.      
  LithiumHighway.AttributesAsChildren = checkBoxAttributesIncluded.Checked; 
  // Step 4 Process to the control. // Step 4 Process to the control.
  LithiumHighway.Process(this.lithiumControl.Root);                        

  this.lithiumControl.Root.Move(new Point(20-this.lithiumControl.Root.X, 
    Convert.ToInt32(this.lithiumControl.Height/2)-this.lithiumControl.Root.Y));

  // See the Lithium Example for this Node level highlighter, 
  // otherwise comment out.            
  ColoringVisitor visitor = new ColoringVisitor(); 

  lithiumControl.BreadthFirstTraversal(visitor);

}
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:

<?xml version='1.0' encoding='utf-8' ?>
<Top CodeProject='online'>
   <Child index='1'>Child data</Child>
   <Other Show='f'>Other Data</Other>
   <Final attr1='This' attr2='is' attr3='Radio' attr4='Clash'/>
</Top>

The class 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

OmegaMan
Web Developer
United States United States
After finding myself with lots of time after a cataclysmic event I have turned to doing programming to help fill the hours.

Comments and Discussions

 
Questionprint the lithium control PinmemberMember 432832831-Dec-07 20:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 15 Apr 2005
Article Copyright 2005 by OmegaMan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid