Click here to Skip to main content
13,558,664 members
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 15 Apr 2005

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.


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:

  // 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.

  this.lithiumControl.Root.Move(new Point(20-this.lithiumControl.Root.X, 

  // See the Lithium Example for this Node level highlighter, 
  // otherwise comment out.            
  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:

<?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'/>

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.


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


About the Author

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.

You may also be interested in...


Comments and Discussions

GeneralDrawing Recursion Pin
cornholios21-Jun-05 2:56
membercornholios21-Jun-05 2:56 
GeneralRe: Drawing Recursion Pin
Anonymous23-Jun-05 14:29
sussAnonymous23-Jun-05 14:29 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 15 Apr 2005
Article Copyright 2005 by OmegaMan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid