0
votes

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.

2
Could you paste the first few lines of your XML document? Starting at the very first character in the file (and please copy/paste and don't re-type it) - Sean Bright
Do you have the ability to use Linq to XML? (ie are you running .NET 3.0 or higher) - bendewey
I could use Linq to XML as a test. Will be 2.0 in production. Haven't used Linq to XML so I'll need help. - BuddyJoe
Sean, the XML I am using is the ATOM feed you can subscribe to after doing a search on search.twitter.com. As a test you could use search.twitter.com/search.atom?q=test - BuddyJoe

2 Answers

1
votes

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.

1
votes

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.