how to stop processing xml file when error found

Discussion in 'Java' started by John_Woo, Jan 25, 2006.

  1. John_Woo

    John_Woo Guest

    Hi,

    I'm using apache DefaultHandler SAX to interpret xml file.

    supposed the xml file as:

    <a>....</a>
    <a>...</a>
    <a>...</a>
    ....
    <a>...</a>

    and the dtd as

    <!ELEMENT a EMPTY>

    namely not allowing PCDATA:

    </a>no letter here<a></a>

    there are some methods in this handler, such as

    public void startElement()
    public void endElement( String namespaceURI,
    String localName, String qName ) throws SAXException
    public void error(SAXParseException e) throws SAXException {
    }
    ...

    for every <a></a>, all above methods involved to process them. but the
    hanlders reports the error

    org.xml.sax.SAXParseException: The content of element type "a" must
    match....

    at the end of processing xml file.

    I'm wondering,

    1. why it reports the error that late?
    2. how to stop processing xml file whenever error found?

    --
    Thanks lots
    John
    Toronto
     
    John_Woo, Jan 25, 2006
    #1
    1. Advertising

  2. John_Woo

    Oliver Wong Guest

    "John_Woo" <> wrote in message
    news:...
    > Hi,
    >
    > I'm using apache DefaultHandler SAX to interpret xml file.
    >
    > supposed the xml file as:
    >
    > <a>....</a>
    > <a>...</a>
    > <a>...</a>
    > ...
    > <a>...</a>
    >
    > and the dtd as
    >
    > <!ELEMENT a EMPTY>
    >
    > namely not allowing PCDATA:
    >
    > </a>no letter here<a></a>
    >
    > there are some methods in this handler, such as
    >
    > public void startElement()
    > public void endElement( String namespaceURI,
    > String localName, String qName ) throws SAXException
    > public void error(SAXParseException e) throws SAXException {
    > }
    > ..
    >
    > for every <a></a>, all above methods involved to process them. but the
    > hanlders reports the error
    >
    > org.xml.sax.SAXParseException: The content of element type "a" must
    > match....
    >
    > at the end of processing xml file.
    >
    > I'm wondering,
    >
    > 1. why it reports the error that late?


    Probably your SAX parser is first checking that the XML is well formed,
    and then only afterwards checking if it is valid. This is generally
    reasonable behaviour, because there's no point in checking for validity if
    the XML is not even wellformed. An example of a not well formed XML
    document:

    <xml>
    <<><><><><<><><>>><><
    </xml>

    > 2. how to stop processing xml file whenever error found?


    Code the intelligence for error detection in your SAX event handling
    methods.

    - Oliver
     
    Oliver Wong, Jan 25, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    775
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,648
    mr_organic
    Apr 9, 2004
  3. Bomb Diggy
    Replies:
    0
    Views:
    472
    Bomb Diggy
    Jul 28, 2004
  4. Will
    Replies:
    1
    Views:
    15,439
    Thomas Weidenfeller
    Nov 2, 2004
  5. Angus
    Replies:
    5
    Views:
    477
    Ben Bacarisse
    Jul 18, 2010
Loading...

Share This Page