0

I have to read an XML file, but it has ':' in the first node.I am getting this error when I am trying to load the file using XDocument or XElement or xmldocument.I do not know how to resolve this issue.

string _filePath= @"C:\testfile.xml";
XDocument xDoc = XDocument.Load(_filePath);

"The ':' character, hexadecimal value 0x3A, cannot be included in a name. Line 1, position 6".

My XML document:

<?xml:stylesheet type="text/xsl" href="\\10.189.41.02\g$\XMLTest-Viewer.xsl"?>
<TestXml>
//More data here
 </TestXml>

If I remove the colon manually I can load the file successfully, is there a way to load the file with the ':' and without changing the XML file?

user3874424
  • 3
  • 1
  • 6

1 Answers1

2

The correct processing-instruction name is xml-stylesheet, not xml:stylesheet. Colons in processing instruction names are not allowed in well-formed XML - or to put it another way, you are trying to read a file that is not XML.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thank you I will load the file stream as a string and do a replace and then load the xml file. Thank you .. I love your book XSLT 2.0 and XPATH 2.0 4th edition. – user3874424 Feb 23 '18 at 14:06