Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

how to stop processing xml file when error found

Thread view: 
John_Woo - 25 Jan 2006 14:41 GMT
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
Oliver Wong - 25 Jan 2006 19:19 GMT
> Hi,
>
[quoted text clipped - 36 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.