XmlTextReader fails on reading DOCTYPE?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • keldan

    #1

    XmlTextReader fails on reading DOCTYPE?

    I am hoping someone on this list can shed some light on
    the below issue for me. I am using XmlTextReader to read
    from an XML file. Unfortunately, an exception is thrown
    ("Index was outside the bounds of the array.") when the
    reader reaches the DOCTYPE. If I remove it everything
    works fine. Should I be handling the DOCTYPE someway
    before I read the DOCTYPE? Any insight would be greatly
    appreciated. I have provided a sample XML document plus
    some simple code.

    Cheers,

    ------------------ Begin Document ------------------------
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE ONIXmessage
    SYSTEM "http://www.editeur.org/onix/2.0/short/onix-
    international.d td">
    <ONIXmessage>
    <header>
    <m173>398393939 3</m173>
    <m174>Me Vendor</m174>
    <m175>Full Name</m175>
    <m180>1</m180>
    <m182>200306221 017</m182>
    <m183>Descripti on</m183>
    </header>
    <product>
    <a001>076150187 7</a001>
    <a002>04</a002>
    <b004>076150187 7</b004>
    <b005>978076150 1862</b005>
    <b012>BC</b012>
    <b028>The Michael Story</b028>
    <b029>What's It Like To Be Me</b029>
    <contributor>
    <b034>1</b034>
    <b035>A01</b035>
    <b036>Michael Muffett</b036>
    <b037>Muffett , Michael</b037>
    <b039>Michael </b039>
    <b040>Muffett </b040>
    <b043>L.</b043>
    </contributor>
    <b059>eng</b059>
    <b061>1000</b061>
    <b064>FIC000000 </b064>
    <b079>Muffett Publishing</b079>
    <imprint>
    <b241>02</b241>
    <b243>PL</b243>
    <b079>Muffett Publishing</b079>
    </imprint>
    <b081>Muffett Publishing</b081>
    <b003>1995101 8</b003>
    <supplydetail >
    <j136>2013975 </j136>
    <j137>Random House</j137>
    <j138>CA</j138>
    <j141>IP</j141>
    <j143>2003101 8</j143>
    <j145>24</j145>
    <price>
    <j148>01</j148>
    <j151>260.95</j151>
    <j152>CAD</j152>
    </price>
    </supplydetail>
    </product>
    </ONIXmessage>
    -------------------- End Document ----------------------

    -------------------- Begin Code ------------------------
    public static void loadDocument(st ring fileName)
    {
    XmlTextReader onixTextReader
    = new XmlTextReader(f ileName);
    try
    {
    onixTextReader. Read();
    MessageBox.Show ("Declaratio n: " +
    onixTextReader. NodeType.ToStri ng());
    onixTextReader. Read();
    MessageBox.Show ("Second
    Line WhiteSpace: " + onixTextReader. NodeType.ToStri ng());
    onixTextReader. ReadString
    ();
    MessageBox.Show
    (onixTextReader .NodeType.ToStr ing());
    }
    catch(Exception e)
    {
    MessageBox.Show (e.Message);
    }
    ---------------------- End Code --------------------------
  • Kathleen Dollard

    #2
    Re: XmlTextReader fails on reading DOCTYPE?

    Have you gotten this solved?

    I don't think the problem is the DOCTYPE element itself. It is in the
    XMLNodeType enum, and the XMLTextReader.R ead documentation happens ot
    include it. Which specific line of code throws the exception?

    --
    Kathleen Dollard
    Microsoft MVP
    Author "Code Generation in Microsoft .NET"


    "keldan" <anonymous@disc ussions.microso ft.com> wrote in message
    news:004301c3c8 a0$e9c28db0$a10 1280a@phx.gbl.. .[color=blue]
    > I am hoping someone on this list can shed some light on
    > the below issue for me. I am using XmlTextReader to read
    > from an XML file. Unfortunately, an exception is thrown
    > ("Index was outside the bounds of the array.") when the
    > reader reaches the DOCTYPE. If I remove it everything
    > works fine. Should I be handling the DOCTYPE someway
    > before I read the DOCTYPE? Any insight would be greatly
    > appreciated. I have provided a sample XML document plus
    > some simple code.
    >
    > Cheers,
    >
    > ------------------ Begin Document ------------------------
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <!DOCTYPE ONIXmessage
    > SYSTEM "http://www.editeur.org/onix/2.0/short/onix-
    > international.d td">
    > <ONIXmessage>
    > <header>
    > <m173>398393939 3</m173>
    > <m174>Me Vendor</m174>
    > <m175>Full Name</m175>
    > <m180>1</m180>
    > <m182>200306221 017</m182>
    > <m183>Descripti on</m183>
    > </header>
    > <product>
    > <a001>076150187 7</a001>
    > <a002>04</a002>
    > <b004>076150187 7</b004>
    > <b005>978076150 1862</b005>
    > <b012>BC</b012>
    > <b028>The Michael Story</b028>
    > <b029>What's It Like To Be Me</b029>
    > <contributor>
    > <b034>1</b034>
    > <b035>A01</b035>
    > <b036>Michael Muffett</b036>
    > <b037>Muffett , Michael</b037>
    > <b039>Michael </b039>
    > <b040>Muffett </b040>
    > <b043>L.</b043>
    > </contributor>
    > <b059>eng</b059>
    > <b061>1000</b061>
    > <b064>FIC000000 </b064>
    > <b079>Muffett Publishing</b079>
    > <imprint>
    > <b241>02</b241>
    > <b243>PL</b243>
    > <b079>Muffett Publishing</b079>
    > </imprint>
    > <b081>Muffett Publishing</b081>
    > <b003>1995101 8</b003>
    > <supplydetail >
    > <j136>2013975 </j136>
    > <j137>Random House</j137>
    > <j138>CA</j138>
    > <j141>IP</j141>
    > <j143>2003101 8</j143>
    > <j145>24</j145>
    > <price>
    > <j148>01</j148>
    > <j151>260.95</j151>
    > <j152>CAD</j152>
    > </price>
    > </supplydetail>
    > </product>
    > </ONIXmessage>
    > -------------------- End Document ----------------------
    >
    > -------------------- Begin Code ------------------------
    > public static void loadDocument(st ring fileName)
    > {
    > XmlTextReader onixTextReader
    > = new XmlTextReader(f ileName);
    > try
    > {
    > onixTextReader. Read();
    > MessageBox.Show ("Declaratio n: " +
    > onixTextReader. NodeType.ToStri ng());
    > onixTextReader. Read();
    > MessageBox.Show ("Second
    > Line WhiteSpace: " + onixTextReader. NodeType.ToStri ng());
    > onixTextReader. ReadString
    > ();
    > MessageBox.Show
    > (onixTextReader .NodeType.ToStr ing());
    > }
    > catch(Exception e)
    > {
    > MessageBox.Show (e.Message);
    > }
    > ---------------------- End Code --------------------------[/color]


    Comment

    • keldan

      #3
      re:XmlTextReade r fails on reading DOCTYPE?

      Sadly I have not solved this issue yet. For the life of me I can't
      understand what is wrong. The the pointer for the reader can't seem
      to read past the DOCTYPE. If i use a while loop:

      while(!reader.E OF)
      {
      reader.Read()
      MessageBox.Show (reader.NodeTyp e.ToString());
      }

      It will read the XML declaration, the whitespace that comes after the
      declaration and then an exception is thrown from the reader.Read()
      when the pointer for the reader points to the next node (which I am
      assuming is the DOCTYPE).

      The output from the Stack Trace is:

      at System.XmlScann er.ScanDtdConte nt()
      at System.Xml.Sche ma.DtdParser.Sc anDtdContent()
      at System.Xml.Sche ma.DtdParser.Pa rseDtdContent()
      at System.Xml.Sche ma.DtdParser.Pa rseDocTypeDecl( )
      at System.Xml.Sche ma.DtdParser.Pa rse()
      at System.Xml.XmlT extReader.Parse Dtd(XmlScanner scanner)
      at System.Xml.XmlT extReader.Parse Tag()
      at System.Xml.XmlT extReader.Parse Root()
      at System.Xml.XmlT extReader.Read( )
      at MainMenuForm1.l oadDocument(Str ing fileName) in C:\vs projects\
      mainmenuform\fo rm1.cs:line 326

      line 326 is reader.Read();

      As I said earlier for the life of me I can't understand why it can't
      read past the DOCTYPE. It's such a simple while loop statement that
      just outputs the nodetype to a MessageBox. I am new to using the
      System.Xml namespace so any more light you can shed on this matter
      will be greatly appreciated - I am at quite confused with this
      problem. I have gone over the online documentation, visited
      messageboards and can find no solution to this problem.

      Cheers,

      Mick



      ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
      http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
      ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

      Comment

      • Martin Honnen

        #4
        Re: XmlTextReader fails on reading DOCTYPE?



        keldan wrote:
        [color=blue]
        > Sadly I have not solved this issue yet. For the life of me I can't
        > understand what is wrong. The the pointer for the reader can't seem
        > to read past the DOCTYPE. If i use a while loop:
        >
        > while(!reader.E OF)
        > {
        > reader.Read()
        > MessageBox.Show (reader.NodeTyp e.ToString());
        > }
        >
        > It will read the XML declaration, the whitespace that comes after the
        > declaration and then an exception is thrown from the reader.Read()
        > when the pointer for the reader points to the next node (which I am
        > assuming is the DOCTYPE).
        >
        > The output from the Stack Trace is:
        >
        > at System.XmlScann er.ScanDtdConte nt()
        > at System.Xml.Sche ma.DtdParser.Sc anDtdContent()
        > at System.Xml.Sche ma.DtdParser.Pa rseDtdContent()
        > at System.Xml.Sche ma.DtdParser.Pa rseDocTypeDecl( )
        > at System.Xml.Sche ma.DtdParser.Pa rse()
        > at System.Xml.XmlT extReader.Parse Dtd(XmlScanner scanner)
        > at System.Xml.XmlT extReader.Parse Tag()
        > at System.Xml.XmlT extReader.Parse Root()
        > at System.Xml.XmlT extReader.Read( )
        > at MainMenuForm1.l oadDocument(Str ing fileName) in C:\vs projects\
        > mainmenuform\fo rm1.cs:line 326
        >
        > line 326 is reader.Read();
        >[/color]

        As far as I see it currently the XmlTextReader reads in the DTD from
        http://www.editeur.org/onix/2.0/shor...ernational.dtd and fails
        to parse it.
        I tried validating the XML in your first post with MSXML 4 and it didn't
        have any problems with the DTD so there might be a bug in .NET's DTD parser.

        --

        Martin Honnen
        http://JavaScript.FAQTs.com/

        Comment

        Working...