C# and XML Document

  • Thread starter news.microsoft.com
  • Start date
N

news.microsoft.com

I am having problems with the following code. I am able to open the xml
document and read it into memory and if I step through the code and look at
the variables, I can see that the XML document is correct. What is
happening is that what is being returned into TableName is
"System.Xml.XmlElement" If I look at the variables in the autos window, I
can see the following in InnerXML, <FOLDERNAME>Member</FOLDERNAME> etc.
Folders =
Doc.SelectSingleNode("SCHEMA").SelectSingleNode("FOLDER").SelectSingleNode("SUBFOLDERS").ChildNodes;

TableList = new ArrayList();

foreach(XmlNode Folder in Folders)

{

TableName = Folder.SelectSingleNode("FOLDERNAME").ToString();

TableList.Add(TableName);

}

return TableList;



Thanks

Bill
 
J

John Saunders

news.microsoft.com said:
I am having problems with the following code. I am able to open the xml
document and read it into memory and if I step through the code and look at
the variables, I can see that the XML document is correct. What is
happening is that what is being returned into TableName is
"System.Xml.XmlElement" If I look at the variables in the autos window, I
can see the following in InnerXML, <FOLDERNAME>Member</FOLDERNAME> etc.
Folders =
Doc.SelectSingleNode("SCHEMA").SelectSingleNode("FOLDER").SelectSingleNode("SUBFOLDERS").ChildNodes;

TableList = new ArrayList();

foreach(XmlNode Folder in Folders)

{

TableName = Folder.SelectSingleNode("FOLDERNAME").ToString();

TableList.Add(TableName);

}

return TableList;

You seem to be assuming that XmlNode.ToString will return the value of the
node. This is clearly not the case.

You want the InnerText property of the XmlNode.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top