Solved

JAXB XML Parsing Question

Posted on 2011-03-01
7
423 Views
Last Modified: 2013-11-19
Is there any way to configure JAXB to, during parsing of an xml document, ignore any text following the closing tag? It seems to ignore any number of spaces following the closing tag, but even one non-space character causes it to throw a SAXParseException.  We have a few xml documents with characters following the closing tag, but otherwise they are fine. Until we can clean them up, it would be great to be able to throw a switch somewhere to say, when you reach the closing tag, forget anything that might be beyond it.  This exception is being thrown durng unmarshalling.  
0
Comment
Question by:whandley
  • 3
  • 3
7 Comments
 
LVL 26

Accepted Solution

by:
mrcoffee365 earned 500 total points
Comment Utility
We have not found a way to do this.  What we do is scrub the xml before sending it to the parser.  Or in some cases, sending it to the parser, catching the exception, scrubbing, then sending it to the parser again.
0
 
LVL 10

Expert Comment

by:Hegemon
Comment Utility
Please correct me if I am wrong, but it looks like illegitimate (non-whitespace) characters after closing tags make the document not well-formed, so, strictly speaking, it is no longer a valid XML document and cannot be processed by XML parser.

Either the document needs to be made valid XML by scrubbing it  or a non-XML parser used.

Problems of this sort can be expected when working with SGML documents that may look like XML but are not well formed.

0
 
LVL 26

Expert Comment

by:mrcoffee365
Comment Utility
Yes -- I already gave that answer.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Expert Comment

by:Hegemon
Comment Utility
My point was not about scrubbing it per se but rather about the document not being an XML document, hence XML parsing not applicable.
0
 
LVL 26

Expert Comment

by:mrcoffee365
Comment Utility
XML docs come in many forms.   It's still an XML doc even if it has some characters in the file after the closing tag.  It is not a well-formed XML doc, which is what the asker was asking about.

As you get more experience with XML docs, you'll find that many are not well-formed, and the developers have to have strategies to deal with that.
0
 
LVL 10

Expert Comment

by:Hegemon
Comment Utility
"Definition: A data object is an XML document if it is well-formed, as defined in this specification.", from here http://www.w3.org/TR/REC-xml/#sec-well-formed.

Hence not well formed - not an XML
0
 
LVL 5

Expert Comment

by:Plk_In_EE
Comment Utility
Hi there
even if there gs a white space before the <xml tag in the document the sax parser will fail
better we send a well formatted xml to parser . open the xml in a browser to if its valid oNe Or not
good luck
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now