relational dataset to XML Treeview CTL src file

killopereet

New Member
Hey guys, <BR><BR>I'm trying to take a relational dataset and output its contents to an xml src file for the TreeView web control. I've got my dataSet and relations down and was planning on just creating an XmlDataDocument and writing it out, but i realized this isn't going to give me the formatting I need for the Treeview to use it as a src. So, here's where I'm a little confused. Do i apply an XSLT Transform to my dataset or use some other method to output the xml file in the correct format? <BR><BR>Thanks, <BR><BR>])ryI usually just response.write out the xml for the file. Check out the example here:<BR>http://www.aspalliance.com/jamesavery/webcontrols/treeviewp2.aspxOk, I read the article, it looks great, just one question:<BR><BR>I'm pulling my data from SQL server, loading it into the dataset and adding my relations. Is there any semi-automated way to take advantage of my parent/child relationships in the dataset? This tree could conceivably drill down 4 or 5 levels, so it'd be nice to take advantage of any automation possible. <BR><BR>Thanks again, <BR><BR>])ryI have a funtion that will create the XML. It uses the XMLTextWriter object instead of Response.Writes for a little more control. My Database is a table with IDs and ParentIDs that is previously sorted. Here's a stripped version of the function for readability. Let me know if you need the whole thing.<BR><BR>void RStoXML(OleDbDataReader DR, String FileName) {<BR><BR>XmlTextWriter writer = new XmlTextWriter (FileName, null);<BR>writer.Formatting = Formatting.Indented;<BR><BR>writer.WriteStartDocument();<BR>writer.WriteStartElement("TREENODES");<BR><BR>while (DR.Read()) { <BR><BR>writer.WriteStartElement("treenode"); <BR>writer.WriteAttributeString("Text", DR["Title"].ToString());<BR>writer.WriteEndElement(); <BR>}<BR><BR>writer.WriteEndElement();<BR>writer.WriteEndDocument();<BR><BR>writer.Flush();<BR>writer.Close();<BR>DR.Close();<BR>}Hmm, this is actually how I was going to originally work with it, but now i'm up in the air as to which route I should take. Do I physically create the xml file on the system (this example) or use the .aspx src idea given in James' article ... I guess I wouldn't mind the full source to compare the two methods if you wouldn't mind? <BR><BR>Thanks John,<BR><BR>])ryHey guys I too am trying to work with the treeview to get the XML to display correctly. What I am doing is as node source having aspx page that just does response writes of XML statements from a database query like you two were talking about.<BR><BR>However I am not sure what the data should look like for multi tiered data. Could you post some more code or your XML file of say your id and parentid things that might go as far as 3 or 4 deep so I can see how the XML is organized.<BR><BR>Thanks<BR>RyanHey Ryan,<BR><BR>I actually ended up going the other direction (using the XmlTextWriter as John suggested), but the xml should look the same whether you use the .aspx or the way I did it. Here is what a trimmed version of my output currently looks like (it goes 3 deep):<BR><BR><?xml version="1.0"?><BR><TREENODES><BR> <treenode Type="Root" Text="NCH Germany"><BR> <treenode Text="Home" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=302" Type="File" /><BR> <treenode Text="Unternehmen" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=303" Type="Folder"><BR> <treenode Text="Untern Sub" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=303:9" Type="File" /><BR> <treenode Text="Untern Sub Page" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=303:7" Type="File" /><BR> <treenode Text="Untern Sub Page 2" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=303:8" Type="File" /><BR> </treenode><BR> <treenode Text="Hersteller" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=304" Type="File" /><BR> <treenode Text="Handel -" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=305" Type="File" /><BR> <treenode Text="Produkte" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=306" Type="File" /><BR> <treenode Text="Presse" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=307" Type="File" /><BR> <treenode Text="Stellen" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=308" Type="File" /><BR> <treenode Text="Kontakt" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=309" Type="File" /><BR> <treenode Text="Couponing" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=310" Type="Folder"><BR> <treenode Text="Couponing Sub Page" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=310:5" Type="File" /><BR> </treenode><BR> <treenode Text="Clearing" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=311" Type="File" /><BR> <treenode Text="Planning" NavigateURL="cms_content_edit.aspx?siteID=39&pageLvlMap=312" Type="File" /><BR> </treenode><BR>...<BR><BR></TREENODES><BR><BR><BR>I also have a TreeNodeTypes xml file that the ctrl is referring to:<BR><BR><TREENODETYPES><BR> <TreeNodeType type="root" imageUrl="webControls/treeView/images/root.gif" /><BR> <TreeNodeType type="folder" ExpandedImageUrl="webControls/treeView/images/folderopen.gif" imageUrl="webControls/treeView/images/folderclosed.gif" /><BR> <TreeNodeType type="subFolder" ExpandedImageUrl="webControls/treeView/images/foldergreyopen.gif" imageUrl="webControls/treeView/images/foldergreyclosed.gif" /><BR> <TreeNodeType type="file" imageUrl="webControls/treeView/images/html.gif" /><BR> <TreeNodeType type="subFile" imageUrl="webControls/treeView/images/htmlsm.gif" /><BR></TREENODETYPES><BR><BR>Hth,<BR><BR>])ry<BR>
 
Back
Top