You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by je...@kanisa.com on 2001/06/19 19:27:08 UTC

RE: DOMParser does not report errors for XML that are not well-fo rmed

Peter,
You could also try this out with the MemParse sample code that comes along
with the package. If you modify the
string in gXMLInMemBuf variable in MemParse.cpp from a well-formed XML
string to a not well-formed one and try running the sample code, you will
see the behavior that I am seeing. That is, it does not throw an
XMLException ..... is this expected?
-Jeetu


> -----Original Message-----
> From: Peter A. Volchek [mailto:PeterV@ti.com.od.ua]
> Sent: Tuesday, June 19, 2001 10:19 AM
> To: xerces-c-dev@xml.apache.org
> Subject: Re: DOMParser does not report errors for XML that 
> are not well-formed
> 
> 
> ----- Original Message -----
> From: <je...@kanisa.com>
> To: <xe...@xml.apache.org>
> Sent: Tuesday, June 19, 2001 7:31 PM
> Subject: DOMParser does not report errors for XML that are 
> not well-formed
> 
> 
> > I am using a DOMParser instance to load XML from a string 
> or a file to a
> DOM
> > by calling the parse(InputSource...) method on the string. 
> When the XML
> > string is not well-formed, I do not get any exceptions (I 
> am catching
> > XMLException while parsing).
> >
> > So I looked at the MemParse sample code which uses a 
> SAXParser instance to
> > do the same thing and which has also set error handlers and document
> > handlers on the SAXParser instance. I modified the XML string in the
> sample
> > code so that it is no more well-formed. It too did not 
> report any errors
> as
> > well. Is this an expected behaviour? If so, then does one 
> have to set
> custom
> > document handlers on a parser instance and throw exceptions 
> if an XML that
> > is parsed is not well-formed? Or is there some other way to 
> do it as well?
> >
> > Thanks in advance,
> > Jeetu
> >
> 
> Didn't you forget to call parser.parse() ?
> Post the piece of code where you initializes the InputSource 
> and sets the
> Parser.
> 
> 
> Peter A. Volchek
> Software Engineer
> Metis International, Inc.
> PeterV@ti.com.od.ua
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: DOMParser does not report errors for XML that are not well-formed

Posted by Tinny Ng <tn...@ca.ibm.com>.
Jeetu,

XML error is not thrown through XMLException, it is issued through Error
Handler.  So in sample Memparse, after you set the MemParseHandler as the
error handler:

    MemParseHandlers handler;
    parser.setErrorHandler(&handler);

The XML error will be issued through MemParseHandlers::fatalError.

I modified the gXmlInMemBuf by adding some leading spaces before xml decl, and
got the expected error message:

E:\>memparse

Fatal Error at (file prodInfo, line 1, char 9): The XML or Text declaration
must start at line/colum
n 1/1

Finished parsing the memory buffer containing the following XML statements:

   <?xml version='1.0' encoding='ascii'?>
<!DOCTYPE company [
<!ELEMENT company     (product,category,developedAt)>
<!ELEMENT product     (#PCDATA)>
<!ELEMENT category    (#PCDATA)>
<!ATTLIST category idea CDATA #IMPLIED>
<!ELEMENT developedAt (#PCDATA)>
]>

<company>
    <product>XML4C</product>
    <category idea='great'>XML Parsing Tools</category>
    <developedAt>
      IBM Center for Java Technology, Silicon Valley, Cupertino, CA
    </developedAt>
</company>


Parsing took 100 ms (0 elements, 0 attributes, 0 spaces, 0 characters).

Tinny



jeetu.gulati@kanisa.com wrote:

> Peter,
> You could also try this out with the MemParse sample code that comes along
> with the package. If you modify the
> string in gXMLInMemBuf variable in MemParse.cpp from a well-formed XML
> string to a not well-formed one and try running the sample code, you will
> see the behavior that I am seeing. That is, it does not throw an
> XMLException ..... is this expected?
> -Jeetu
>
> > -----Original Message-----
> > From: Peter A. Volchek [mailto:PeterV@ti.com.od.ua]
> > Sent: Tuesday, June 19, 2001 10:19 AM
> > To: xerces-c-dev@xml.apache.org
> > Subject: Re: DOMParser does not report errors for XML that
> > are not well-formed
> >
> >
> > ----- Original Message -----
> > From: <je...@kanisa.com>
> > To: <xe...@xml.apache.org>
> > Sent: Tuesday, June 19, 2001 7:31 PM
> > Subject: DOMParser does not report errors for XML that are
> > not well-formed
> >
> >
> > > I am using a DOMParser instance to load XML from a string
> > or a file to a
> > DOM
> > > by calling the parse(InputSource...) method on the string.
> > When the XML
> > > string is not well-formed, I do not get any exceptions (I
> > am catching
> > > XMLException while parsing).
> > >
> > > So I looked at the MemParse sample code which uses a
> > SAXParser instance to
> > > do the same thing and which has also set error handlers and document
> > > handlers on the SAXParser instance. I modified the XML string in the
> > sample
> > > code so that it is no more well-formed. It too did not
> > report any errors
> > as
> > > well. Is this an expected behaviour? If so, then does one
> > have to set
> > custom
> > > document handlers on a parser instance and throw exceptions
> > if an XML that
> > > is parsed is not well-formed? Or is there some other way to
> > do it as well?
> > >
> > > Thanks in advance,
> > > Jeetu
> > >
> >
> > Didn't you forget to call parser.parse() ?
> > Post the piece of code where you initializes the InputSource
> > and sets the
> > Parser.
> >
> >
> > Peter A. Volchek
> > Software Engineer
> > Metis International, Inc.
> > PeterV@ti.com.od.ua
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: DOMParser does not report errors for XML that are not well-formed

Posted by "Peter A. Volchek" <Pe...@ti.com.od.ua>.
----- Original Message -----
From: <je...@kanisa.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, June 19, 2001 8:27 PM
Subject: RE: DOMParser does not report errors for XML that are not
well-formed


> Peter,
> You could also try this out with the MemParse sample code that comes along
> with the package. If you modify the
> string in gXMLInMemBuf variable in MemParse.cpp from a well-formed XML
> string to a not well-formed one and try running the sample code, you will
> see the behavior that I am seeing. That is, it does not throw an
> XMLException ..... is this expected?
> -Jeetu
>

I changed the first tag to <company1>. The errors were printed as expected
(see below)

    Error at (file prodInfo, line 10, char 10): Unknown element 'company1'
    Error at (file prodInfo, line 10, char 10): Root element different from
DOCTYPE
    Fatal Error at (file prodInfo, line 16, char 10): Expected end of tag
'company1'
    Finished parsing the memory buffer containing the following XML
statements:


Be sure that you have changed the data not inside #ifdef OS390 section.
Regards.


Peter A. Volchek
Software Engineer
Metis International, Inc.
PeterV@ti.com.od.ua




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org