Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > URGENT: Multidimensional hierarchical XML in TreeView

Reply
Thread Tools

URGENT: Multidimensional hierarchical XML in TreeView

 
 
Björn Bengtsson
Guest
Posts: n/a
 
      08-20-2003
Hello!

I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and
the TreeView control.
I have two tables; one describing the products and one describing their
relationships. A product may consist of multiple other products. So far
everything is great. But one product may exist as a subproduct to multiple
parent products.

My tables:
Products(prod_id, nam)
ProductRelation(prod_id, parent_id)

My relation:
Product 1 consists of Product 2 and Product 3.
Product 4 consists of Product 5 AND Product 3.

My data in the table ProductRelation:
product 2, product 1
product 3, product 1
product 5, product 4
product 3, product 4 // This is what causes the error; product 3.

My intentions:
Retrieving the data from a MS SQL Server 7 and transforming it into XML, a
TreeView control is to be used to display the hierarchical data. The problem
is that I don't know how to make this work. Storing it and retrieving it is
of no problem, but the fact that product 3 is nested in two different places
makes it a bit hard.
Think of it as a manufacturer who makes different products as tables and
chairs and nails. Nails are used in both tables and chairs...

My code:
//DataSet
DataSet ds = new DataSet("COMPONENTDS");

//Fill DataSet
da.Fill(ds, "COMPONENT");

// Create a recursive data relation.
DataColumn col1 = ds.Tables[0].Columns["prod_id"];
DataColumn col2 = ds.Tables[0].Columns["parent_id"];
DataRelation drel = new DataRelation("PRODUCTS_RECURSIVE", col1, col2,
true);
drel.Nested = true;
ds.Relations.Add(drel);

//XmlDocument to hold XML generated from DataSet
XmlDocument objDoc = new XmlDocument();

//Load XML
objDoc.LoadXml(ds.GetXml());

//Create XslTransform object
XslTransform objXSL = new XslTransform();

//Load XSLT stylesheet
objXSL.Load(Server.MapPath("hierarchy.xslt"));

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

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

//Set TreeView's TreeNodeSrc property to get XML from StringWriter.
// tvTest2 is the TreeView control.
tvTest2.TreeNodeSrc = writer.ToString();

//Bind TreeView
tvTest2.DataBind();

//Close StringWriter
writer.Close();


Some notes:
This code works fine if I don't insist on having a product as a sub product
to multiple products. The drel.Nested = true makes it so easy. (: However,
this won't work like I want it. I've tried setting ds.EnforceConstraints =
false, but that only throws an error when trying the ds.GetXml().
I found the methodology at this URL:
http://aspalliance.com/joteke/treevi...e/article.aspx

Can anyone help me with this problem?
How do I EASILY get this kind of multidimensional parent-child relationship
converted to hierarchical XML so that the TreeView control can display it?

- Björn


 
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
SQL: Inserting hierarchical data from XML Masya ASP .Net 0 01-07-2009 07:39 AM
How to build hierarchical XML from DataSet Options gamesforums@hotmail.com XML 0 06-12-2008 10:57 AM
XML schema hierarchical key constraint verfication drmccoy@home.se XML 0 05-31-2006 02:16 PM
Creating Reports based on hierarchical XML file John XML 2 11-18-2004 04:54 PM
Perl modules for multi hierarchical XML processing Ivan Dwyer XML 1 07-25-2004 10:01 AM



Advertisments