Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] SAXParser Parsing Problem

Ross Bleakney

2004-09-29

Replies:

I get the following error when I parse my XML:

org.jdom.IllegalTargetException: The target "xml" is not legal for JDOM/XML
Processing Instructions: Processing instructions cannot have a target of
"xml" in any combination of case. (Note that the "<?xml ... ?>" declaration
at the beginning of a document is not a processing instruction and should
not be added as one; it is written automatically during output, e.g. by
XMLOutputter.).

The xml has, of course, this at the top:

<?xml version="1.0"?>

If I remove this, something really strange happens. I get the XML inside an
HTML document. For example, if the XML is this:

<junk>abcd</junk>

I get this (after parsing):

<html><body><junk>abcd</junk></body></html>

Here is my code:

    SAXBuilder saxBuilder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser");
    Document document = saxBuilder.build(file);
    ...

I've tried with the default parser and got the same result (I haven't tried
other parsers).

Has anyone seen either one of these problems?

Thanks,
Ross

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.