Solved

JAXB XML Parsing Question

Posted on 2011-03-01
7
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 35017463
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
ID: 35018614
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 27

Expert Comment

by:mrcoffee365
ID: 35019773
Yes -- I already gave that answer.
0
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 
LVL 10

Expert Comment

by:Hegemon
ID: 35020010
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 27

Expert Comment

by:mrcoffee365
ID: 35021033
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
ID: 35025543
"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
ID: 35056185
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 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