jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes XML Parsing problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Parsing problem" Watch "XML Parsing problem" New topic

XML Parsing problem

Chris Tjoumas

Joined: Dec 17, 2003
Posts: 11
I am using the javax.xml.parsers library to parse an XML file. I am doing this from an applet, so I have created a VBScript to generate the XML file. In my applet, I am trying to parse the XML file like this:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse( "http://devweb.nhlbi.nih.gov/LCEChris/Applet/Scripts/GetImages.asp?examNum=8381" );
traverse( doc );
} catch ( SAXException sxe ) {
} catch ( ParserConfigurationException pce ) {
} catch ( IOException ioe ) {
} // end try-catch
As you can see, the script name is GetImages.asp. I put that url with the query string param and the correct XML is generated. But, I am getting the following error:
org.xml.sax.SAXParseException: XML declaration may only begin entities.
I searched on that and there was a site that explained that this means that there could be whitespace preceding my xml declaration (http://community.voxeo.com/vxml/docs/vxml_1.3/loggermessages.htm). I viewed the source in IE and there was, in fact, two line breaks before my <?xml version="1.0"?> declaration.
Does anyone know what I can do to get around this problem? I don't see in my VBScript what would be causing the line breaks to be inserted. Or, is there another XML Parser for Java that would ignore these line breaks (if this is actually what is really causing the problem)?
Chris Tjoumas

Joined: Dec 17, 2003
Posts: 11
Ah...I figured it out. I had an include directive above my xml declaration and used <enter> to put the xml declaration on the next line. Apparently the xml declaration needs to be right next to the include directive (on the same line).
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Moved to the XML forum.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link: http://aspose.com/file-tools
subject: XML Parsing problem
It's not a secret anymore!