Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Recursive Data Help

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
GB
Hello there, this is a newbie question.

I have got a set of data that shows the department hierarchy. In VB I have treeview control that shows this nicely, but now we want it in ASP, so someone suggested XML!
I have created an XML file, that I fails when you try to view it in IE and not sure what to do.

<?xml version='1.0' encoding='ISO-8859-1'?>
<USER>
<MANAGERID>
0
</MANAGERID>
<ID>
1
</ID>
<NAME>
User A
</NAME>
</USER>
<USER>
<MANAGERID>
1
</MANAGERID>
<ID>
2
</ID>
<NAME>
User B
</NAME>
</USER>
<USER>
<MANAGERID>
1
</MANAGERID>
<ID>
3
</ID>
<NAME>
User C
</NAME>
</USER>

Am I doing this right? Can anyone help me?

Thanks
 
I don't know what version of IE your using but if your working with XML get the latest version. On Win2k IE version 6 this is the error message i get from your XML file:

Code:
Only one top level element is allowed in an XML document. Error processing resource 'file:///C:/Research/test2.xml'. Line 13, Position 2 

<USER>

This is all the information you should need to fix the problem with your file.

-pete
 
yep, sorry I missed that. How do I apply a template that will show the hierarchy?
 
>> How do I apply a template that will show the hierarchy?

Not sure what your asking, but if you want IE to display your data after being transformed using a XSL(T) stylesheet put a stylesheet reference element at the top of your XML file.
Code:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;mytransform.xsl&quot; ?>

-pete
 
The only thing that is missing in your document is a root node

ex:

<USERS>
<USER>
...
</USER>
<USER>
...
</USER>
<USER>
...
</USER>
</USERS>

Eric
 
How are you generating the XML file? Is it possible to do more of the work representing the hierarchy within the file itself something like this:
[tt]
<USERS>
<USER>
<ID>1</ID>
<NAME>User A</NAME>
<SUBORDINATES>
<USER>
<ID>2</ID>
<NAME>User B</NAME>
</USER>
<USER>
<ID>3</ID>
<NAME>User C</NAME>
<SUBORDINATES>
<USER>
<ID>4</ID>
<NAME>User D</NAME>
</USER>
</SUBORDINATES>
</USER>
</SUBORDINATES>
</USER>
</USERS>
[/tt]
This would make your template easier to write. I've done something similar transforming to become (using a perl script).

-- Chris Hunt
 
Thanks Chris, that might be an idea, although I'm still a little unsure as how to write my template as I'm a complete XML newbie!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top