This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Parsing problem" Watch "XML Parsing problem" New topic
Author

XML Parsing problem

Chris Tjoumas
Greenhorn

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 ) {
sxe.printStackTrace();
} catch ( ParserConfigurationException pce ) {
pce.printStackTrace();
} catch ( IOException ioe ) {
ioe.printStackTrace();
} // 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)?
Thanks!
Chris
Chris Tjoumas
Greenhorn

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"
Sheriff

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


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
wood burning stoves
 
subject: XML Parsing problem
 
Similar Threads
build DOM Object of a file whose path is given
DOM Parser
Line breaks being removed
XML Parsing error
Inserting node in XMl and retaining doc type information