SAX Parser and <?xml version="1.0" ?>

J

John Smith

I have produced a SAX parser using Xerces to scan some external XML
documents. It works okay except when the file contains "<?xml version="1.0"
?>". If this is in the file I get the error:
[Fatal Error] :4:6: The processing instruction target matching
"[xX][mM][lL]" is not allowed.
org.xml.sax.SAXParseException: The processing instruction target matching
"[xX][mM][lL]" is not allowed.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
Why is this and how do I get round it.

Thanks

Jon
 
M

Martin Honnen

John said:
I have produced a SAX parser using Xerces to scan some external XML
documents. It works okay except when the file contains "<?xml version="1.0"
?>". If this is in the file I get the error:
[Fatal Error] :4:6: The processing instruction target matching
"[xX][mM][lL]" is not allowed.
org.xml.sax.SAXParseException: The processing instruction target matching
"[xX][mM][lL]" is not allowed.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
Why is this and how do I get round it.

Where does the XML contain that? That is the so called XML declaration
and an XML document is supposed to start with the XML declaration so the
parser shouldn't give an error if that is the start of the XML document.

If it occurs later in the document then the parser is right, it is an
error and not allowed as it would then be a processing instruction but
the name xml is not allowed for a processing instruction.
 
J

John C. Bollinger

John said:
I have produced a SAX parser using Xerces to scan some external XML
documents. It works okay except when the file contains "<?xml version="1.0"
?>". If this is in the file I get the error:
[Fatal Error] :4:6: The processing instruction target matching
"[xX][mM][lL]" is not allowed.
org.xml.sax.SAXParseException: The processing instruction target matching
"[xX][mM][lL]" is not allowed.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
Why is this and how do I get round it.

The XML declaration must be the *very first* thing in the XML file (per
the XML spec). No blank lines, whitespace, control characters, etc. may
precede it. In other words, the '<' must be at offset 0 from the
beginning of the file. The error message you describe is typical when
this is not the case.

If you have files that do not conform to the XML specification in this
regard then they are syntactically incorrect, and Xerces is right to
reject them. Fix the files. If you somehow handle correct XML files in
a manner that makes them appear to violate the spec, then fix your
handling. If you think there is some other problem then you'll need to
provide more details, and probably enough code to demonstrate the
problem and allow us to duplicate it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top