none
'--' is an unexpected token. The expected token is '>'.

    Question

  • Hi All, i know that this Question has been asked quite a lot in this forum but unfortunately none of them resolved my issue.  I have an XML file placed on a server and i send a webrequest to fetch the file and load the the xml file.  EVerything works great on my PC, but suddenly we were having issues at one our customer sites where when the above webrequest is made and the when the load method gets called it is throwing a DTD parser exception which primarily says

     

    <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-alt:"Times New Roman"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> ]: Exception Message : '--' is an unexpected token. The expected token is '>'. Line 31, position 3. **Exception Stack Trace : at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.Throw(Exception e)
    at System.Xml.DtdParser.Throw(Int32 curPos, String res, String[] args)
    at System.Xml.DtdParser.ThrowUnexpectedToken(Int32 pos, String expectedToken1, String expectedToken2)
    at System.Xml.DtdParser.ScanClosingTag()
    at System.Xml.DtdParser.GetToken(Boolean needWhiteSpace)
    at System.Xml.DtdParser.ParseEntityDecl()
    at System.Xml.DtdParser.ParseSubset()
    at System.Xml.DtdParser.ParseExternalSubset()
    at System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset)
    at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
    at System.Xml.XmlTextReaderImpl.DtdParserProxy.Parse(Boolean saveInternalSubset)
    at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
    at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
    at System.Xml.XmlTextReaderImpl.Read()
    at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
    at System.Xml.XmlDocument.Load(XmlReader reader)
    at System.Xml.XmlDocument.Load(Stream inStream)

    In previous posts people suggested to check for & in the file &amp; but my XML file has none of those characters, but still the customer has this issue. And it doesn't happen at our place or at any other customer but with one (it is the same XML file by the way). Any ideas why this would be??

    Any help would be greatly appreciated

    Sush

    Thursday, March 24, 2011 8:29 PM

Answers

  • I doubt that the issue is related to 32bit versus 64bit OS. I rather think that sometimes your request for the XML document fails and the server responds with an error code and an error page which is a HTML document. What exactly fails I don't know, check the status code and we will know.
    MVP Data Platform Development My blog
    Saturday, March 26, 2011 11:57 AM

All replies

  • Hi All, i know that this Question has been asked quite a lot in this forum but unfortunately none of them resolved my issue.  I have an XML file placed on a server and i send a webrequest to fetch the file and load the the xml file.  EVerything works great on my PC, but suddenly we were having issues at one our customer sites where when the above webrequest is made and the when the load method gets called it is throwing a DTD parser exception which primarily says

     

    <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-alt:"Times New Roman"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> ]: Exception Message : '--' is an unexpected token. The expected token is '>'. Line 31, position 3. **Exception Stack Trace : at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.Throw(Exception e)
    at System.Xml.DtdParser.Throw(Int32 curPos, String res, String[] args)
    at System.Xml.DtdParser.ThrowUnexpectedToken(Int32 pos, String expectedToken1, String expectedToken2)
    at System.Xml.DtdParser.ScanClosingTag()
    at System.Xml.DtdParser.GetToken(Boolean needWhiteSpace)
    at System.Xml.DtdParser.ParseEntityDecl()
    at System.Xml.DtdParser.ParseSubset()
    at System.Xml.DtdParser.ParseExternalSubset()
    at System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset)
    at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
    at System.Xml.XmlTextReaderImpl.DtdParserProxy.Parse(Boolean saveInternalSubset)
    at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
    at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
    at System.Xml.XmlTextReaderImpl.Read()
    at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
    at System.Xml.XmlDocument.Load(XmlReader reader)
    at System.Xml.XmlDocument.Load(Stream inStream)

    In previous posts people suggested to check for & in the file &amp; but my XML file has none of those characters, but still the customer has this issue. And it doesn't happen at our place or at any other customer but with one (it is the same XML file by the way). Any ideas why this would be??

    Any help would be greatly appreciated

    Sush


    SO far the PC's that have reported this issue are all Windows 7 Profesional 64bit machines.

     

    Thursday, March 24, 2011 8:57 PM
  • Any chance of seeing the Xml?
    Thursday, March 24, 2011 11:09 PM
  • The stack trace suggests there is a syntax error in the DTD. Try to isolate the problem, then post a minimal but complete XML document allowing us to reproduce the problem. At least show us how line 31 mentioned in the error message looks.
    MVP Data Platform Development My blog
    Friday, March 25, 2011 1:36 PM
  • <BetaModuleSelector>
      <option Title="Alpha" Display="YES" Password="1" AppMode="SELECT" />
      <Modules>
          <Module Name="ABC" Mode="FORCEDWIN" ></Module>
        <Module Name="123" Mode="FORCEDWIN" ></Module>    
        <Module Name="XYZ" Mode="FORCEDWIN" ></Module>
        <Module Name="Calibration" Mode="FORCEDWIN" ></Module>
        <Module Name="WEF" Mode="WIN" ></Module>
        <Module Name="Cash" Mode="WIN" ></Module>
        <Module Name="Sheet" Mode="WIN" ></Module>
        <Module Name="Search" Mode="FORCEDWIN" ></Module>
        <Module Name="Job" Mode="FORCEDWIN" ></Module>
        <Module Name="Complete" Mode="FORCEDWIN" ></Module>
        <Module Name="Consignment" Mode="FORCEDWIN" ></Module>
        <Module Name="Contract" Mode="FORCEDWIN" ></Module>
        <Module Name="Contract Balance Transfer" Mode="FORCEDWIN" ></Module>
        <Module Name="Data Analysis" Mode="WIN" ></Module>
        <Module Name="Deductions" Mode="FORCEDWIN" ></Module>
        <Module Name="Records" Mode="FORCEDWIN" ></Module>
        <Module Name="Time" Mode="FORCEDWIN" ></Module>
        <Module Name="Change" Mode="FORCEDWIN" ></Module>
        <Module Name="Adjust" Mode="FORCEDWIN" ></Module>
        <Module Name="Maintenance" Mode="FORCEDWIN" ></Module>
        <Module Name="Retire Sale" Mode="FORCEDWIN" ></Module>
        <Module Name="Separation" Mode="FORCEDWIN" ></Module>
        <Module Name="Journal" Mode="FORCEDWIN" ></Module>
        <Module Name="GA" Mode="FORCEDWIN" ></Module>
        <Module Name="Reconciliation" Mode="FORCEDWIN" ></Module>
        <Module Name="DescriptionFile" Mode="FORCEDWIN" ></Module>
        <Module Name="OverHeads" Mode="FORCEDWIN" ></Module>
        <Module Name="Inquiry Account" Mode="FORCEDWIN" ></Module>   
       </Modules>
    </BetaModuleSelector>
    Friday, March 25, 2011 4:27 PM


  • Above is my file and i have tried reproducing the issue on 64bit machines. So far i have tested on xp and vista and they seem to be Okay. Will test today on a Windows 7 PC to see if that reproduces the issue.

     

    Please let me know if you find any problems

     


    Friday, March 25, 2011 4:29 PM
  • I don't think that sample causes the error you describe. There must be a DOCTYPE node in your markup, otherwise you would not get the stack trace you posted.
    MVP Data Platform Development My blog
    Friday, March 25, 2011 5:45 PM
  • Well that is what wondered me as well. It does not have any doctype in this particular XML file and it still logs this exception every time the file loads.  For all i know that the user's PC has msxml3 and msxml6 dll's.

     

    There is another XML file as well which also is causing us issues and that does have a DOCTYP. Below is the one.  it also gets the same error described as above

     

    <?xml version="1.0" encoding="UTF-8"?>
    <Forms>
        <FormsCollection Name="FORM">
             <Form Name="&amp;Service Application                    "/>
             <Form Name="&amp;Commercial Application                     " />
        </FormsCollection>   
    </Forms>

     

     

    Friday, March 25, 2011 6:07 PM
  • I don't see any DOCTYPE node in your latest sample. Are you sure it is XML that is parsed when you get the error? I suspect something goes wrong on the server you access and it returns a HTML error document with a HTML DOCTYPE, which the XML parser then fails to parse as HTML syntax is different from XML syntax. That's a guess of course, there could be other reasons.

    MVP Data Platform Development My blog
    Friday, March 25, 2011 6:19 PM
  • Martin i am sorry, yes it doesn't have a doctype. I wanted to say that it does have encoding mentioned in the xml file unlike the earlier one and i was thinking may be this encoding could be a reason for the issue.

    I am accessing the file using

     System.Net.WebRequest request = System.Net.WebRequest.Create("http://" + App.ServerName + "//XYZ//abc.xml");
                    request.Timeout = 25000;
                    System.Net.WebResponse response = request.GetResponse();
                  
                    Stream stream = response.GetResponseStream();
                    if (stream != null)
                    {
                        System.Xml.XmlDocument _docXml = new System.Xml.XmlDocument();
                        _docXml.Load(stream);

    }

    File exists on the server and is during when i call Load is when it is having issues i believe.   Is it something to do with any setting for that folder or file on IIS on the server that i am accessing the file from?

     

     

     

    Friday, March 25, 2011 6:29 PM
  • I suspect the file is not found or some other error occurs and the server does not send XML back but rather a HTML document. Check

      ((HttpWebResponse)response).StatusCode

    and

     

      ((HttpWebResponse)response).ContentType

     

    when the problem occurs.

    As for my suspicion, when I use the code

          XmlDocument doc = new XmlDocument();
          doc.Load(args[0]);

    to load a HTML document

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <h1>Test</h1>
    </body>
    </html>
    

    then the error is

    Unhandled Exception: System.Xml.XmlException: '--' is an unexpected token. The e
    xpected token is '>'. Line 81, position 5.
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.T
    hrow(Exception e)
       at System.Xml.DtdParser.Throw(Int32 curPos, String res, String[] args)
       at System.Xml.DtdParser.ThrowUnexpectedToken(Int32 pos, String expectedToken1
    , String expectedToken2)
       at System.Xml.DtdParser.ScanClosingTag()
       at System.Xml.DtdParser.GetToken(Boolean needWhiteSpace)
       at System.Xml.DtdParser.ParseEntityDecl()
       at System.Xml.DtdParser.ParseSubset()
       at System.Xml.DtdParser.ParseExternalSubset()
       at System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset)
       at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
       at System.Xml.DtdParser.System.Xml.IDtdParser.ParseInternalDtd(IDtdParserAdap
    ter adapter, Boolean saveInternalSubset)
       at System.Xml.XmlTextReaderImpl.ParseDtd()
       at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean prese
    rveWhitespace)
       at System.Xml.XmlDocument.Load(XmlReader reader)
       at System.Xml.XmlDocument.Load(String filename)

    so pretty much what you get, besides the exact line number. Based on that and the description so far you need to check the response you get when the error occurs.

     

     


    MVP Data Platform Development My blog
    Friday, March 25, 2011 6:41 PM
  • Martin i will check it. Thank you for the Prompt Response.

    if that is indeed the case, then why is happening on only one PC at the customer, but it does not happen on rest of them.  Does the stream that i use to get the file from the sever returned differ on a 64bit PC and a 32bit PC.

     

    As i mentioned earlier, this particular issues for now has been reported only on two pc's which are 64bit machines?

     

     

    Friday, March 25, 2011 6:59 PM
  • I doubt that the issue is related to 32bit versus 64bit OS. I rather think that sometimes your request for the XML document fails and the server responds with an error code and an error page which is a HTML document. What exactly fails I don't know, check the status code and we will know.
    MVP Data Platform Development My blog
    Saturday, March 26, 2011 11:57 AM
  • I have found this same error, and it is only fixed when I remove the '&' from my xml file.  I would love to be able to parse the file better so that it can have an & in the file.
    Friday, October 19, 2012 7:16 PM