Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
John Smith - 07 Mar 2005 10:43 GMT
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
Martin Honnen - 07 Mar 2005 15:01 GMT
> 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"
[quoted text clipped - 5 lines]
>         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.

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

John C. Bollinger - 07 Mar 2005 15:03 GMT
> 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"
[quoted text clipped - 5 lines]
>         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.

Signature

John Bollinger
jobollin@indiana.edu



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.