Populating a treeview contol from an xml file

J

Jason Shohet

Hi,
I'm trying to populate a treeview with an xml file. I have an xsl file
associated with the xml file but the control asks for an TreeNodXsltSrc can
anyone please tell me how to generate an XSLT file from an Xml file.

Thanks for your help
 
M

Manfred Braun

Hi,

appended is a snippet from a sample application, and I use it successfully.
You simply do not need to use both, the xml-source and the xslt-source. So
far I understand you, ypu have already done the transformation into xml?


Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)

//===================================================================
XmlDocument objDoc=new XmlDocument();
objDoc.Load(xmlTreeNodesFilename);

//Create XslTransform object and load stylesheet:
XslTransform objXSL=new XslTransform();
objXSL.Load(xslTreeNodemapperFilename );

//StringWriter to temporarily hold result of the transformation:
StringWriter writer = new StringWriter();

//One can use this line for debugging, writing directly to the
output-stream:
//XmlTextWriter writer = new XmlTextWriter(Response.Output);

//Apply transformation with no arguments and dump results to StringWriter.
objXSL.Transform(objDoc.CreateNavigator(), null, writer);

//Set TreeView's TreeNodeSrc property to get XML from StringWriter and
bind data:
TreeView1.TreeNodeTypeSrc = xmlDefaultNodeTypesFilename;
TreeView1.TreeNodeSrc = writer.ToString();

TreeView1.DataBind();

//Close StringWriter
writer.Close();

//======================================================================
 
J

Jason Shohet

Manfred,
Thanks for your help. But I have a few questions. In your code you refer to
xmlTreeNodesFilename
and xslTreeNodemapperFilename which I take to mean the XML and XSL files
respectively. What does xmlDefaultNodeTypesFilename refer to.
Below are my XML and Xsl files how would they apply to your code
Thanks again,
Jason Shohet


************************XML FILE**********************
<?xml version="1.0" standalone="yes" ?>
<HEPClasses xmlns="http://tempuri.org/HEPClass.xsd">
<HEPClass>
<CLASS_NO>101.1</CLASS_NO>
<TITLE>Name of Class </TITLE>
<COURSE_HRS>12</COURSE_HRS>
<DESCRIPTION>Class Description</DESCRIPTION>
<GROUP_NO>1</GROUP_NO>
<GROUP_NAME>Name of Group</GROUP_NAME>
<ACTIVE>true</ACTIVE>
</HEPClass>


*********************************XSL FILE ***************************
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<IGTree>
<TreeProperties>
<!--All the stuff goes here-->
</TreeProperties>
<Styles>
<!--All the stuff goes here-->
</Styles>
<Levels/>
<IslandLevels/>
<Nodes>
<xsl:apply-templates/>
</Nodes>
</IGTree>
</xsl:template>

<xsl:template match="HEPClass">
<Node>
<xsl:apply-templates select="CLASS_NO"/>
<Nodes>
<xsl:apply-templates select="TITLE"/>
<xsl:apply-templates select="COURSE_HRS"/>
<xsl:apply-templates select="DESCRIPTION"/>
<xsl:apply-templates select="GROUP_NO"/>
<xsl:apply-templates select="GROUP_NAME"/>
<xsl:apply-templates select="ACTIVE"/>
</Nodes>
</Node>
</xsl:template>

<xsl:template match="CLASS_NO">
<Text><xsl:value-of select="."/></Text>
</xsl:template>
<xsl:template match="TITLE">
<Node>
<Text><xsl:value-of select="."/></Text>
</Node>
</xsl:template>
<xsl:template match="COURSE_HRS">
<Node>
<Text><xsl:value-of select="."/></Text>
</Node>
</xsl:template>
<xsl:template match="DESCRIPTION">
<Node>
<Text><xsl:value-of select="."/></Text>
</Node>
</xsl:template>
<xsl:template match="GROUP_NO">
<Node>
<Text><xsl:value-of select="."/></Text>
</Node>
</xsl:template>
<xsl:template match="GROUP_NAME">
<Node>
<Text><xsl:value-of select="."/></Text>
</Node>
</xsl:template>
<xsl:template match="ACTIVE">
<Node>
<Text><xsl:value-of select="."/></Text>
</Node>
</xsl:template>

</xsl:stylesheet>
 
M

Manfred Braun

Hi Jason,

sorry and sad to say, I am not the xml-guy... ;-)
If you mail me, I would send you my xml and xsl file, so you could see, what
I convert from/to. For your case, I am not sure, what you would like to see
in the tree. You cannot have other "personal" properties, than the
"NodeData", what I use to pass information to the client-side. My
"DefaultNodetypes" are just simply three types of nodes, which apper into my
tree, a open book, a clodes book and a html image. To can use them instead
of giving each node that decoration. In my case, I always specify only these
thrre type, while I am adding nodes. I add nodey danymically, after I start
with that handful coming from my "StaricNodes...." file/s.

Hope this help,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top