Microsoft KB Archive/318351

= PRB: You Receive XmlTextReader Error Message When Colon Appears in Processing Instruction =

Article ID: 318351

Article Last Modified on 9/17/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.0

-



This article was previously published under Q318351



The following .NET Framework Class LIbrary namespace is referenced in this aritcle:

System.XML



SYMPTOMS
If you use the XmlTextReader to read an Extensible Markup Language (XML) document, and the document contains a processing instruction with a colon, you may receive the following error message:

'xml:stylesheet' is an invalid name for a processing instruction. Line 1, position 3.



CAUSE
This behavior is by design.



RESOLUTION
To work around this problem, do one of the following:   Do not use colon in the processing instruction. Instead, use a hyphen. Both Microsoft and W3C recommend this method:  should be changed to  For more information about the W3C recommendation, browse to the following W3C Web site:

http://www.w3.org/TR/xml-stylesheet/

  If you cannot change the XML, turn off the namespace on XmlTextReader before you read the XML, and then set the namespace back to its original value after you finish reading: //before calling read, set XmlTextReader.Namespace = false

//after you have read, set XmlTextReader.Namespaces=true 



Steps to Reproduce Behavior
 Open Microsoft Visual Studio .NET.</li> Create a new Windows application in Microsoft Visual Basic .NET. Form1 is added to the project by default.</li> Place a Command button on Form1. Change the Name property of the button to btnTest .</li>  Use the Imports statement on the System.Xml namespaces, so that you are not required to qualify declarations in those namespaces later in your code. Add the following code to the &quot;General Declarations&quot; section of Form1: Imports System.Xml </li>  Copy and paste the following code in the btnTest_Click event: Try Dim reader As New XmlTextReader(&quot;c:\textr.xml&quot;) While reader.Read If reader.NodeType = XmlNodeType.Element Then MessageBox.Show(reader.Name) End If           End While Catch ex As Exception MessageBox.Show(ex.Message) End Try </li>  Copy and paste the following XML into Notepad, and then save the file as Textr.xml in your C: root directory: <?xml:stylesheet type=&quot;text/xsl&quot; href=&quot;test.xsl&quot;?> <book genre='novel' ISBN='1-861001-57-5'> Pride And Prejudice <book genre='novel' ISBN='1-81920-21-2'> Hook </li> Save the project, and then run the project.</li> Click btnTest, and then notice the error message.</li>  Open Textr.xml, and then modify the following line: <?xml:stylesheet type=&quot;text/xsl&quot; href=&quot;test.xsl&quot;?> to the following: <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;test.xsl&quot;?> </li> Save the XML file, and then run the project.</li> Click btnTest, and then notice the element names.</li></ol>

Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

Keywords: kbprb KB318351

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.