views:

385

answers:

2

In .NET what does it mean if you LoadXml() into the XmlDocument object and then ParentNode and DocumentType are null?

Also, I get this as the answer to xmldoc.FirstChild.Value:
version="1.0" encoding="utf-8"

Is this right? Been a while since I have done any XML DOM stuff. The file is encoded UTF-8. Think that shouldn't be an issue. Is there a simple true/false validation method for my doc?

UPDATE:
If the NodeType is Element how do you return the "tag name"?

CURRENT THINKING:
xmldoc.ChildNodes[1].Name;

I noticed the Name property is Get only. Whats the best tool to use if you wanted to swap the root tag for something else (like 'feed' to 'container'), but wanted something a little more lightweight than XSLT, and not simple text/replace. Would still like to see a LINQ to XML example. Thanks for everyone's help. Guess its been longer than I thought since I have looked at the XML stuff in .NET.

+1  A: 

From the MSDN documentation, XmlDocument.ParentNode always returns null - the document itself is the root, so it has no parent. The DocumentType property returns the DOCTYPE tag, which your example doesn't have.

Dave
I'm confused. See update.
tyndall
+1  A: 

The root element is always accessible through the XmlDocument.DocumentElement property. The name of the root element could be determined using XmlDocument.DocumentElement.LocalName string property.

If you want to rename the root element, you're better off using another instance of XmlDocument, add a root element using XmlDocument.CreateNode, call it what you like, then loop children of the original document's root element and use the CloneNode (bool deep) method, in conjunction with the XmlNode.ImportNode method to copy the rest of the original document to the new document.

baretta