views:

562

answers:

2

I'm trying to parse and load an XML document, however I'm getting this exception when I call the parse method on the class that extends XmlObject. Unfortunately, it gives me no ideas of what element is unexpected, which is my problem.

I am not able to share the code for this, but I can try to provide more information if necessary.

+1  A: 

Not being able to share code or input data, you may consider the following approach. That's a very common dichotomic approach to diagnostic, I'm afraid, and indeed you may readily have started it...

Try and reduce the size of the input XML by removing parts of it, ensuring that the underlying XML document remains well formed and possibly valid (if validity is required in your parser's setup). If you maintain validity, this may require to alter [a copy of] the Schema (DTD or other), as manditory elements might be removed during the cut-and-try approach... BTW, the error message seems to hint more at a validation issue that a basic well-formedness assertion issue.

Unless one has a particular hunch as to the area that triggers the parser's complaint, we typically remove (or re-add, when things start working) about half of what was previously cut or re-added.

You may also start with trying a mostly empty file, to assert that the parser does work at all... There again is the idea to "divide to prevail": is the issue in the XML input or in the parser ? (remembering that there could be two issues, one in the input and one in the parser, and thtat such issues could even be unrelated...)

Sorry to belabor basic diagnostics techniques which you may well be fluent with...

mjv
in other words, "delete stuff until it works"...?
skaffman
Yep. And sttart adding back, when it starts working. Simple but efficient and generic !
mjv
A: 

You should check the arguments you are passing to the method parse(); If you are directly passing a string to parse or file or inputstream accordingly (File/InputStream/String) etc.

anand