Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Populating a treeview contol from an xml file

Reply
Thread Tools

Populating a treeview contol from an xml file

 
 
Jason Shohet
Guest
Posts: n/a
 
      07-21-2003
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


 
Reply With Quote
 
 
 
 
Manfred Braun
Guest
Posts: n/a
 
      07-21-2003
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

(E-Mail Removed)
(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();

//================================================== ====================
" Jason Shohet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>


 
Reply With Quote
 
 
 
 
Jason Shohet
Guest
Posts: n/a
 
      07-22-2003
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 xmlnssl="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>


 
Reply With Quote
 
Manfred Braun
Guest
Posts: n/a
 
      07-22-2003
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

(E-Mail Removed)
(Remove the anti-spam-underscore to mail me!)


" Jason Shohet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 xmlnssl="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>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Treeview : Showing Updating... while populating nodes drop ASP .Net 0 09-18-2006 03:22 PM
problem in populating treeview --asp.net 2.0 Erland ASP .Net 0 09-15-2006 02:26 PM
Treeview contol in asp.net 2.0 with checkboxes pushpi ASP .Net Web Controls 1 07-04-2006 02:03 PM
Populating treeview Mike ASP .Net 0 05-31-2006 12:54 PM
populating treeview menu from db(treenode not defined error) naijacoder naijacoder ASP .Net 1 09-15-2004 03:11 AM



Advertisments