xke wrote:
Quote:
How can I check that a document has XMLDeclaration ?
i.e. it has <?xml version="1.0" encoding="utf-8"?> in the beginning |
If you load the document with XmlReader then you can check the
XmlNodeType after the first Read call e.g. pseudo code
public static bool HasXmlDeclaration (string fileName)
{
using (XmlReader reader = XmlReader.Create(fileName))
{
reader.Read();
return reader.NodeType == XmlNodeType.XmlDeclaration;
}
}
Console.WriteLine(HasXmlDeclaration("file.xml"))
If you use System.Xml.XmlDocument then you can check whether
xmlDocumentInstance.FirstChild is an XmlDeclaration node.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/