Treeview and XML

  • Thread starter Thread starter Evan Kontos
  • Start date Start date
E

Evan Kontos

I am trying to implement a Treeview w/an XML file and I even copied and
pasted examples from MSDN but can't get them to work. Any suggestions
welcome.

XML File

<TREENODES>
<TREENODE TEXT="Document-1">
<TREENODE TEXT="Folder-1" EXPANDED="true">
<TREENODE TEXT="Document-2" />
<TREENODE TEXT="Document-3" />
</TREENODE>
<TREENODE TEXT="Document-4">
</TREENODES>


Control Source

<iewc:TreeView id="TreeView1" style="Z-INDEX: 102; LEFT: 168px;
POSITION: absolute; TOP: 120px" runat="server"
TREENODESRC="NavigateTree.xml"></iewc:TreeView>

Error

Server Error in '/Manager' Application.
------------------------------------------------------------------------
--------

The data at the root level is invalid. Line 1, position 1.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The data at the root level
is invalid. Line 1, position 1.




Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Evan,
Will you help me, I want to use a Treeview on a webpage. I saw it with aspx
and scripting but not with VB.net, can you tell me where I can find this.
Cor
 
Hi Evan,

You may try to modified the XML file as follows.
<TREENODES>
<TREENODE TEXT="Document-1"/>
<TREENODE TEXT="Folder-1" EXPANDED="true">
<TREENODE TEXT="Document-2" />
<TREENODE TEXT="Document-3" />
</TREENODE>
<TREENODE TEXT="Document-4"/>
</TREENODES>


[Note: the node in xml file should end with /
e.g.
<TREENODE TEXT="Document-1"/>
and
<TREENODE TEXT="Folder-1" EXPANDED="true">
</TREENODE>
is correct syntax.
In addition the <TREENODE TEXT="Document-1"/> is the brief form of
<TREENODE TEXT="Document-1"></TREENODE>.

If you have further related question please feel free to contact me.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
Peter,
Tried the change that you recommended but I still get the same error
message. This is also at the top of the XML file

<?xml version='1.0'?>

and the rest of the file:

<TREENODES>
<TREENODE TEXT="Document-1"/>
<TREENODE TEXT="Folder-1" EXPANDED="true">
<TREENODE TEXT="Document-2" />
<TREENODE TEXT="Document-3" />
</TREENODE>
<TREENODE TEXT="Document-4"/>
</TREENODES>


any more suggestions?

Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Hi Evan,

I can not reproduce the problem. Here is my test code. I tested on
VS.NET2003.
I hope you can create a new project and perform the test and let me know
the result.
1.Create a new Webapplication
2.Drag the TreeView control to the webform
3.Modified the NavigateTree.xml and yourapp.aspx as follows.
[NavigateTree.xml, please place it in the same directory as the one of
yourapp.aspx]
<?xml version='1.0'?>
<TREENODES>
<TREENODE TEXT="Document-1"/>
<TREENODE TEXT="Folder-1" EXPANDED="true">
<TREENODE TEXT="Document-2" />
<TREENODE TEXT="Document-3" />
</TREENODE>
<TREENODE TEXT="Document-4"/>
</TREENODES>

[yourapp.aspx]
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls"
Assembly="Microsoft.Web.UI.WebControls" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication3.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<iewc:treeview id="TreeView1" style="Z-INDEX: 101; LEFT: 8px; POSITION:
absolute; TOP: 8px" runat="server"
TREENODESRC="NavigateTree.xml"></iewc:treeview></FONT></form>
</body>
</HTML>

Please perform the test and let me know the result. This will help me
narrow down and isolate the problem.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
Peter,
Here is the error that I get. It seems the same. I click on the data
tab at the bottom of the XML page and I see a grid w/the values and it
looks OK. ANy ideas?

The data at the root level is invalid. Line 1, position 1.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The data at the root level
is invalid. Line 1, position 1.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[XmlException: The data at the root level is invalid. Line 1, position
1.]
System.Xml.XmlTextReader.ParseRoot() +295
System.Xml.XmlTextReader.Read() +127
Microsoft.Web.UI.WebControls.TreeView.ReadXmlSrc(String TreeNodeSrc,
String TreeNodeXsltSrc, String strOuter) +136
Microsoft.Web.UI.WebControls.TreeView.ReadTreeNodeXmlSrc() +80
Microsoft.Web.UI.WebControls.TreeView.OnInit(EventArgs e) +90
System.Web.UI.Control.InitRecursive(Control namingContainer) +241
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Page.ProcessRequestMain() +174








Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Hi Evan,

You may try to set the TreeNodeSrc as following to see if this works for
you. [You may delete TREENODESRC="NavigateTree.xml" in the aspx page]
private void Page_Load(object sender, System.EventArgs e)
{
TreeView1.TreeNodeSrc="<?xml version=\"1.0\"?><TREENODES><TREENODE
TEXT=\"Document-1\"/><TREENODE TEXT=\"Folder-1\"
EXPANDED=\"true\"><TREENODE TEXT=\"Document-2\" /><TREENODE
TEXT=\"Document-3\" /></TREENODE><TREENODE
TEXT=\"Document-4\"/></TREENODES>";
TreeView1.DataBind();
}

If this works for you, you may need to see if the user you used to access
the aspx page have the right to access the NavigateTree.xml file. [If you
enable the anonymous access in the Directory Security/Anonymous access and
authentication control, then the user maybe IUSER_COMPUTERNAME.]
You may try to disable the anonymous access and enable the Integrated
Windows authentication.[Note, this will enable the browse to use the login
user account to access the aspx page and the NavigateTree.xml , make sure
the user have the according rights]



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: Evan Kontos <[email protected]>
References: <[email protected]>
X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
Subject: RE: Treeview and XML
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Date: Thu, 04 Sep 2003 09:47:44 -0700
NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:134270
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Peter,
Here is the error that I get. It seems the same. I click on the data
tab at the bottom of the XML page and I see a grid w/the values and it
looks OK. ANy ideas?

The data at the root level is invalid. Line 1, position 1.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The data at the root level
is invalid. Line 1, position 1.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[XmlException: The data at the root level is invalid. Line 1, position
1.]
System.Xml.XmlTextReader.ParseRoot() +295
System.Xml.XmlTextReader.Read() +127
Microsoft.Web.UI.WebControls.TreeView.ReadXmlSrc(String TreeNodeSrc,
String TreeNodeXsltSrc, String strOuter) +136
Microsoft.Web.UI.WebControls.TreeView.ReadTreeNodeXmlSrc() +80
Microsoft.Web.UI.WebControls.TreeView.OnInit(EventArgs e) +90
System.Web.UI.Control.InitRecursive(Control namingContainer) +241
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Page.ProcessRequestMain() +174








Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Peter,
What is it that you have sent me? I use VB and I have no idea what it
is you sent or where I should place it. Please advise in more detail if
you can. Thanks.


Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Hi Evan,

I am sorry that I have not provided the VB.NET code for you in my last post.
I think the problem is caused by that the user account that used to access
the asp page do not have the permission to access the NavigateTree.xml file.
To workaround the problem, you have two methods.

1. The TreeView web control has a TreeNodeSrc property, you may set the
value to the xml file content in the Page_Load event. You may follow the
steps below to have a test.
1.1 Create a new WebApplication and add a TreeView Web Control onto the
WebForm1.aspx
1.2 Double-click on the WebForm1.aspx[not on any control]
1.3 Then the IDE will open the WebForm1.aspx.vb file and located in the
Page_Load Event handle function
1.4 Replace the
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
With
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TreeView1.TreeNodeSrc = "<?xml version='1.0'?><TREENODES><TREENODE
TEXT='Document-1'/><TREENODE TEXT='Folder-1' EXPANDED='true'><TREENODE
TEXT='Document-2' /><TREENODE TEXT='Document-3' /></TREENODE><TREENODE
TEXT='Document-4'/></TREENODES>"
TreeView1.DataBind()
End Sub
1.5 Press F5 to run the WebApplication to see if the problem persists.

2 You may also try to give the user account that used to access the
WebForm1.aspx the right to access the NavigateTree.xml. In this case you
may indicate the TREENODESRC in the aspx page.(i.e. <iewc:treeview
id="TreeView1" style="Z-INDEX: 101; LEFT: 8px; POSITION:
absolute; TOP: 8px" runat="server"
TREENODESRC="NavigateTree.xml"></iewc:treeview>)
For security concern, you may try to disable the anonymous access and
enable the windows integrated authentication. You may achieve that by
following the steps below.
2.1 Run inetmgr in the Run dialog and this will open the Internet
Information Services(IIS) Manager
2.2 Navigated to Internet Information Services/<Computer Name>/Web
Sites/Default Web Site/<WebApplication5>, (This is the application name
that you indicated in the VS.NET IDE),
2.3 Right Click on the WebApplication5 and select Properties, this will
open the WebApplication5 Properties dialog.
2.4 Select Directory security and then select Authentication and access
control section click the Edit button. This will open the Authentication
methods dialog
2.5 Uncheck the Enable anonymous access and check the Integrated Windows
authentication. This will enable the browse use the log on user account to
access the aspx page, I assume the account have the permission to access
the NavigateTree.xml file.
2.6 You may have a try and let me know the result. If you have any related
question please feel free to let me know.
 
Peter,
Thanks for your reply. Your comment below:

Uncheck the Enable anonymous access and check the Integrated Windows
authentication.
Was already set this way. However I don;'t understand the next
sentence:

This will enable the browse use the log on user account to access the
aspx page, I assume the account have the permission to access the
NavigateTree.xml file.

If you can restate this line it would be helpful. Thanks.




Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Peter,
Your first example works fine. If I replace the treenodesource line w/

TreeView1.TreeNodeSrc = "navigatetree.xml"

I get the error below. Could there be some problem w/the parser on my
machine w/regard to the XML?

Server Error in '/Treeview' Application.
------------------------------------------------------------------------
--------

The data at the root level is invalid. Line 1, position 1.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The data at the root level
is invalid. Line 1, position 1.

Source Error:


Line 25: TreeView1.TreeNodeSrc = "navigatetree.xml"
Line 26: ' TreeView1.TreeNodeSrc = "<?xml
version='1.0'?><TREENODES><treenode text='document-1'/><treenode
TEXT='Folder-1' expanded='true'><treenode TEXT='Document-2' /><TREENODE
TEXT='Document-3' /></treenode><treenode
text='document-4'/></TREENODES>"
Line 27: TreeView1.DataBind()
Line 28: End Sub
Line 29:


Source File: e:\inetpub\wwwroot\Treeview\WebForm1.aspx.vb Line: 27

Stack Trace:


[XmlException: The data at the root level is invalid. Line 1, position
1.]
System.Xml.XmlTextReader.ParseRoot() +295
System.Xml.XmlTextReader.Read() +127
Microsoft.Web.UI.WebControls.TreeView.ReadXmlSrc(String TreeNodeSrc,
String TreeNodeXsltSrc, String strOuter) +134
Microsoft.Web.UI.WebControls.TreeView.ReadTreeNodeXmlSrc() +80
Microsoft.Web.UI.WebControls.TreeView.DataBind()
Treeview.WebForm1.Page_Load(Object sender, EventArgs e) in
e:\inetpub\wwwroot\Treeview\WebForm1.aspx.vb:27
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731


It is beginning to sound like a problem w/.NET. Is there a way to get
this escalated as a system bug?



Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Hi Evan,

Usually when you enable anonymous access, the Browser will use the
IUSER_XYZ account to access your web page.(here the computer name is XYZ)
When you disable the anonymous access and enable the Integrated Windows
authentication,i.e. Uncheck the Enable anonymous access and check the
Integrated Windows authentication.
In this case, if you log onto the computer using a account(e.g.
administrator), then the browser will use the administrator account to
access your web page. Hereby, you will have the enough permission to access
the web page as well as the navigatetree.xml.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
Hi Evan,

I can not reproduce the problem, and I did not find known issue about the
problem. In this case I hope you can have a check about two points.
1. Please check if the account you used the access the web page have the
permission to access the navigatetree.xml file. If you disable the
anonymous account and enable the windows integrated authenticatioin, you
will access the web page with the same account you log on to the
computer.(e.g. administrator)
2. Please check the path of the navigatetree.xml.
if you use the navigatetree.xml in such syntax.

TreeView1.TreeNodeSrc = "navigatetree.xml"

the navigatetree.xml should be placed under the same directory as where
WebForm1.aspx placed in.
e.g.
I access my test webapplication using
http://localhost/WebApplication5/WebForm1.aspx
the website lie in the C:\Inetpub\wwwroot\WebApplication5

Then the navigatetree.xml and WebForm1.aspx should be placed in the
C:\Inetpub\wwwroot\WebApplication5.

If you have any related question, please feel free to let me know.




Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
From: Evan Kontos <[email protected]>
References: <[email protected]>
X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
Subject: RE: Treeview and XML
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Date: Sun, 07 Sep 2003 20:25:36 -0700
NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:135359
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Peter,
Your first example works fine. If I replace the treenodesource line w/

TreeView1.TreeNodeSrc = "navigatetree.xml"

I get the error below. Could there be some problem w/the parser on my
machine w/regard to the XML?

Server Error in '/Treeview' Application.
------------------------------------------------------------------------
--------

The data at the root level is invalid. Line 1, position 1.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The data at the root level
is invalid. Line 1, position 1.

Source Error:


Line 25: TreeView1.TreeNodeSrc = "navigatetree.xml"
Line 26: ' TreeView1.TreeNodeSrc = "<?xml
version='1.0'?><TREENODES><treenode text='document-1'/><treenode
TEXT='Folder-1' expanded='true'><treenode TEXT='Document-2' /><TREENODE
TEXT='Document-3' /></treenode><treenode
text='document-4'/></TREENODES>"
Line 27: TreeView1.DataBind()
Line 28: End Sub
Line 29:


Source File: e:\inetpub\wwwroot\Treeview\WebForm1.aspx.vb Line: 27

Stack Trace:


[XmlException: The data at the root level is invalid. Line 1, position
1.]
System.Xml.XmlTextReader.ParseRoot() +295
System.Xml.XmlTextReader.Read() +127
Microsoft.Web.UI.WebControls.TreeView.ReadXmlSrc(String TreeNodeSrc,
String TreeNodeXsltSrc, String strOuter) +134
Microsoft.Web.UI.WebControls.TreeView.ReadTreeNodeXmlSrc() +80
Microsoft.Web.UI.WebControls.TreeView.DataBind()
Treeview.WebForm1.Page_Load(Object sender, EventArgs e) in
e:\inetpub\wwwroot\Treeview\WebForm1.aspx.vb:27
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731


It is beginning to sound like a problem w/.NET. Is there a way to get
this escalated as a system bug?



Evan Kontos | (e-mail address removed)

27 Whitehall St. | 3rd Floor | New York, NY 10004
Tel 212.480.8166 | Fax 212.480.8167 | Personal Fax 786.513.0295
www.comtekcadd.com
 
Hi Evan,

If you post a zip of your project source, I can see whether it causes the
error on my machine.

Regards,
Fergus
 
Back
Top