f



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

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 


0
usenet123 (40)
3/7/2005 10:43:07 AM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

2 Replies
541 Views

Similar Articles

[PageSpeed] 25


John Smith wrote:

> 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.


-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
0
mahotrash (2052)
3/7/2005 3:01:57 PM
John Smith wrote:

> 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.

-- 
John Bollinger
jobollin@indiana.edu
0
jobollin (1557)
3/7/2005 3:03:37 PM
Reply: