Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to stop processing xml file when error found

Reply
Thread Tools

how to stop processing xml file when error found

 
 
John_Woo
Guest
Posts: n/a
 
      01-25-2006
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

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      01-25-2006

"John_Woo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When to stop - how do I work out when to stop processing Angus C Programming 5 07-18-2010 07:40 PM
One File Found, the other Not Found ?!?!?! mcampo84@gmail.com Java 3 08-07-2006 09:49 PM
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM



Advertisments