users
[Top] [All Lists]

RE: [cinjug-users] parsing using jdom

To: "'Jason Kretzer/STAR BASE Consulting Inc.'" <JKretzer@xxxxxxxxxxxxxxx>, <users@xxxxxxxxxx>
Subject: RE: [cinjug-users] parsing using jdom
From: "Robert Casto" <robert@xxxxxxxxxxxxx>
Date: Wed, 21 Apr 2004 17:59:50 -0400
Delivered-to: mailing list users@cinjug.org
In-reply-to: <OF1435DA07.AFF56E45-ON85256E7D.006B90DE-85256E7D.006CAADF@starbaseinc.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Thread-index: AcQn2a5eBGT9nRefScmxFR5KscNk/AAD/gdw

Jason,

 

Wrap the URL stream with a buffered stream and then pass that to the build method. It may get an error by trying to parse the stream before more data is available.

 

Robert Casto
President - CinciJava LLC
Phone: 513-755-2221
FAX: 831-307-7638
robert@xxxxxxxxxxxxx

 

 


From: Jason Kretzer/STAR BASE Consulting Inc. [mailto:JKretzer@xxxxxxxxxxxxxxx]
Sent: Wednesday, April 21, 2004 3:46 PM
To: users@xxxxxxxxxx
Subject: [cinjug-users] parsing using jdom

 


I am using jdom to parse a stream from a url -- the one mentioned in my previous posts.  When I try to parse it, I get the following error.

---------------------------------------
org.jdom.input.JDOMParseException: Error on line 13 of document https://someWebSite.com/giveXML.jsp?someparam=paramOne:
XML declaration may only begin entities.
---------------------------------------

I am using the following code to parse it.

---------------------------------------
SAXBuilder builder = new SAXBuilder();
builder.setValidation(true);
builder.setIgnoringElementContentWhitespace(true);
Document doc = builder.build(url);
---------------------------------------

where url is the url from before.  

After getting this error, printed out the xml document using the following code.

---------------------------------------
InputStreamReader isr = new InputStreamReader(url.openStream());
BufferedReader br = new BufferedReader(isr);

String line = br.readLine();
while(line != null)
{
        System.out.println(line);
        line = br.readLine();
}

br.close();
---------------------------------------

I redirected the output to a file and opened it with IE and it opened fine.  When I tried to parse the file using the above code though I received this error.

---------------------------------------
org.jdom.input.JDOMParseException: Error on line 1 of document file:/output.xml:
Document root element is missing.
---------------------------------------


I have posted a the first few lines of the file, I printed out.  Only some of the element names have been changed.  I also cut off the first 12 lines as they were blank for some reason.  Anyone know what I can do to fix this?

Thanks,

-Jason



<?xml version="1.0" ?>
<!DOCTYPE ROOT_ELEMENT [
<!ELEMENT ROOT_ELEMENT (MESSAGE_ID, ELEMENT_ONE*)>
<!ELEMENT MESSAGE_ID (#PCDATA)>
<!ELEMENT ELEMENT_ONE (TEST_ROOT, TEST_ELEMENT+)>
<!ELEMENT TEST_ELEMENT (TEST_CODE, TEST_VERSION, TEST_ACCESS, TEST_DESCRIPTION?,TEST_PREDECESSOR_CODE?)>
<!ELEMENT TEST_CODE (#PCDATA)>
<!ELEMENT TEST_ROOT (#PCDATA)>
<!ELEMENT TEST_VERSION (#PCDATA)>
<!ELEMENT TEST_ACCESS (#PCDATA)>
<!ELEMENT TEST_DESCRIPTION (#PCDATA)>
<!ELEMENT TEST_PREDECESSOR_CODE (#PCDATA)>
]>

<ROOT_ELEMENT>
<MESSAGE_ID></MESSAGE_ID>
<ELEMENT_ONE>
<TEST_ROOT>some text</TEST_ROOT>
<TEST_ELEMENT>
<TEST_CODE>NE2-C</TEST_CODE>
<TEST_VERSION>Comp</TEST_VERSION>
<TEST_ACCESS>N</TEST_ACCESS>
<TEST_PREDECESSOR_CODE>pred_code</TEST_PREDECESSOR_CODE>
</TEST_ELEMENT>
<TEST_ELEMENT>
<TEST_CODE>NE2</TEST_CODE>
<TEST_VERSION>Secure</TEST_VERSION>
<TEST_ACCESS>Y</TEST_ACCESS>
<TEST_PREDECESSOR_CODE>pred_code other</TEST_PREDECESSOR_CODE>
</TEST_ELEMENT>
</ELEMENT_ONE>
..........

<Prev in Thread] Current Thread [Next in Thread>
  • parsing using jdom, Jason Kretzer/STAR BASE Consulting Inc.
    • RE: [cinjug-users] parsing using jdom, Robert Casto <=