none
An invalid character was found in text content. Error processing resource - XML File

    Pregunta

  •  

    Hi Gurus,

     

    I was reading from a xml doc using Visual basic. I was doing it fine until i got this error message in my browser, when i was trying to open that xml file, i got the following error- An invalid character was found in text content. Error processing resource  'file:///C:/EAL-00056-082.xml'. Line 1, Position...

     

    I tried to look into what was the issue.

    and found that the text that was inside a xml tag, had an apostrophe 's. ie(Land’s Motion) and hence i was not able to see the xml file generated on the browser, once i remove the single quote of the apostrophe i am able to open the document in the browser.

     

    Is there a way how i can overcome this problem of singlequote in the text content of the xml file??? so that i am able to open the file in a browser.

    Can i replace the single quote with something else, How is it handled whille in VB.

     

    Thanking you in Anticipation,

     

    Sachin.

     

    viernes, 04 de julio de 2008 15:03

Respuestas

  • When you load an XML document in a browser like IE then the browser uses its XML parser (in case of IE that parser is MSXML) to check the XML for well-formedness. That particular document where you get the error is not well-formed, probably because it is not properly encoded. You need to fix that at the source so that whoever generates the XML makes sure it is properly encoded and declares the encoding if needed (i.e. when it is not UTF-8 or UTF-16).

    If you want to fix the document at your end then you can't use any XML APIs to do that as the document is not well-formed. And the first thing you need to know to fix the document is the encoding of the document so ask the producer of the document how it is encoded. If you know the encoding then you can read it in with a TextReader and add the XML declaration or change the encoding when saving back. So this overload http://msdn.microsoft.com/en-us/library/ms143456.aspx of the StreamReader constructor which takes a stream and an encoding for instance which you can use once you know the encoding. Or try encodings you suspect to be used.

    To make it clear: the single quote itself is not a problem at all in XML, here is an example document that has it and you can easily load that in IE without getting an error: http://home.arcor.de/martin.honnen/xml/test2008070501.xml

    So the problem is not a single quote but an improperly encoded or declared XML document. You need to find out how the producer of that document encoded the document. So ask in a support forum for Siebel CRM how that software encodes its XML documents or how you can use that software to properly encode the XML documents it produces.

     

    sábado, 05 de julio de 2008 12:39

Todas las respuestas

  • A single quote is allowed in XML in character data but not in names (element and attribute names). So the single quote is not a problem as long as it is properly encoded. So check the encoding of the XML document and make sure it is properly declared in the XML declaration if it is not UTF-8 or UTF-16.

    I am not sure what else we can do, unless you can post a URL to your document.

    Also note that your own post contains two different characters, the character "'" which has Unicode code point 39 and the character "’" which has Unicode code point 8217. Based on that I would guess that your document might for instance be Windows-1252 encoded but does not declare that in its XML declaration and therefore the XML parser correctly gives an error. 

    viernes, 04 de julio de 2008 15:19
  • Hi,

     

    Well let me put it in a better way.
    The xml that i am consuming, is a complex nodelist document which is published by Siebel CRM, and i am consuming that nodelist(xml doc) in Visual Basic for further processing. It does not have any encoding information accept a namespace declaration.
    The doc has complex data in different xml tags. and I am able to view the tags and data in my IE browser.
    but when One of the tag has an apostrophe(single quote, ') inside it, (eg <Name>Donald's</Name>) and due to which i am not able to open the document in a browser.
    so if i want to see the document in the browser in such situations is there anything that i can do to mask the single quote in VB, i mean at my end.
    so that i can see the it in the browser again.


    I hope i am clear about my issue,

    Kind Regards,

    Sachin.

    viernes, 04 de julio de 2008 17:52
  • When you load an XML document in a browser like IE then the browser uses its XML parser (in case of IE that parser is MSXML) to check the XML for well-formedness. That particular document where you get the error is not well-formed, probably because it is not properly encoded. You need to fix that at the source so that whoever generates the XML makes sure it is properly encoded and declares the encoding if needed (i.e. when it is not UTF-8 or UTF-16).

    If you want to fix the document at your end then you can't use any XML APIs to do that as the document is not well-formed. And the first thing you need to know to fix the document is the encoding of the document so ask the producer of the document how it is encoded. If you know the encoding then you can read it in with a TextReader and add the XML declaration or change the encoding when saving back. So this overload http://msdn.microsoft.com/en-us/library/ms143456.aspx of the StreamReader constructor which takes a stream and an encoding for instance which you can use once you know the encoding. Or try encodings you suspect to be used.

    To make it clear: the single quote itself is not a problem at all in XML, here is an example document that has it and you can easily load that in IE without getting an error: http://home.arcor.de/martin.honnen/xml/test2008070501.xml

    So the problem is not a single quote but an improperly encoded or declared XML document. You need to find out how the producer of that document encoded the document. So ask in a support forum for Siebel CRM how that software encodes its XML documents or how you can use that software to properly encode the XML documents it produces.

     

    sábado, 05 de julio de 2008 12:39