Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9031 > unrolled thread

org.xml.sax.SAXParseException: Premature end of file

Started bylaredotornado <laredotornado@zipmail.com>
First post2011-10-20 08:41 -0700
Last post2011-10-20 20:15 +0200
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  org.xml.sax.SAXParseException: Premature end of file laredotornado <laredotornado@zipmail.com> - 2011-10-20 08:41 -0700
    Re: org.xml.sax.SAXParseException: Premature end of file markspace <-@.> - 2011-10-20 10:04 -0700
      Re: org.xml.sax.SAXParseException: Premature end of file laredotornado <laredotornado@zipmail.com> - 2011-10-20 10:59 -0700
        Re: org.xml.sax.SAXParseException: Premature end of file Lew <lewbloch@gmail.com> - 2011-10-20 14:06 -0700
    Re: org.xml.sax.SAXParseException: Premature end of file Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-10-20 20:15 +0200

#9031 — org.xml.sax.SAXParseException: Premature end of file

Fromlaredotornado <laredotornado@zipmail.com>
Date2011-10-20 08:41 -0700
Subjectorg.xml.sax.SAXParseException: Premature end of file
Message-ID<22aef44f-90f0-4fe4-a20e-64f336e4c1b3@g25g2000yqh.googlegroups.com>
Hi,

I'm using Java 6.  I'm trying to parse some well-formed (or at least
that's what I thought) XML but am getting a "SAXParseException:
Premature end of file" exception (below).  The code I'm using is

		xml = xml.trim();
		final InputStream inputStream = new
ByteArrayInputStream(xml.getBytes());
		final DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
		final DocumentBuilder db = dbf.newDocumentBuilder();
		final Document doc = db.parse(xmlInputStream);

The block I'm trying to parse is below.  Can anyone see how it is mal-
formed?  Barring that, do you know a better way of parsing the string?

<div class="">
<label
for="id417474726962757465205b6e616d653d6e616d652c2076616c75653d4c697374696e672052756c652c20706172656e744e6f64653d546578744e6f6465205b746578743d6e756c6c2c20444e6f64653d444e6f6465205b69643d305d5d5d">400</
label><br/>
<input
id="id417474726962757465205b6e616d653d6e616d652c2076616c75653d4c697374696e672052756c652c20706172656e744e6f64653d546578744e6f6465205b746578743d6e756c6c2c20444e6f64653d444e6f6465205b69643d305d5d5d"
name="id417474726962757465205b6e616d653d6e616d652c2076616c75653d4c697374696e672052756c652c20706172656e744e6f64653d546578744e6f6465205b746578743d6e756c6c2c20444e6f64653d444e6f6465205b69643d305d5d5d"
type="text" value="
    		15 months of jun, jul, aug, sep, oct
"   style="width:400px;"  />
</div>

Thanks, - Dave

ps - The error ...

    org.xml.sax.SAXParseException: Premature end of file.
	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
	at com.myco.clearing.commons.xmlparser.XMLParser.parse(XMLParser.java:
53)
	at com.myco.clearing.commons.xmlparser.XMLParser.parse(XMLParser.java:
35)
	at com.myco.clearing.commons.xmlparser.XMLParser.parse(XMLParser.java:
80)
	at com.myco.clearing.commons.xmlparser.XMLParser.parse(XMLParser.java:
35)
	at
com.myco.pplus2.util.XmlToHtmlServiceTest.testInput(XmlToHtmlServiceTest.java:
52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:
41)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:
20)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
28)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
76)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:
50)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
197)

[toc] | [next] | [standalone]


#9038

Frommarkspace <-@.>
Date2011-10-20 10:04 -0700
Message-ID<j7pka5$bqr$1@dont-email.me>
In reply to#9031
On 10/20/2011 8:41 AM, laredotornado wrote:

> I'm using Java 6.  I'm trying to parse some well-formed (or at least
> that's what I thought) XML but am getting a "SAXParseException:


It worked for me.


> Premature end of file" exception (below).  The code I'm using is


No, this is not the code.  There's a syntax error: inputStream and 
xmlInputStream are being confused here, xmlInputStream is not declared.


>
> 		xml = xml.trim();
> 		final InputStream inputStream = new
> ByteArrayInputStream(xml.getBytes());
> 		final DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> 		final DocumentBuilder db = dbf.newDocumentBuilder();
> 		final Document doc = db.parse(xmlInputStream);
>
> The block I'm trying to parse is below.  Can anyone see how it is mal-
> formed?  Barring that, do you know a better way of parsing the string?


Yes, there's a syntax error in the XML.  Construct a proper SSCCE to see it.


[toc] | [prev] | [next] | [standalone]


#9043

Fromlaredotornado <laredotornado@zipmail.com>
Date2011-10-20 10:59 -0700
Message-ID<824e4576-7c4e-4fa4-b7c6-58541513bd5f@f13g2000vbv.googlegroups.com>
In reply to#9038
On Oct 20, 12:04 pm, markspace <-@.> wrote:
> On 10/20/2011 8:41 AM, laredotornado wrote:
>
> > I'm using Java 6.  I'm trying to parse some well-formed (or at least
> > that's what I thought) XML but am getting a "SAXParseException:
>
> It worked for me.
>
> > Premature end of file" exception (below).  The code I'm using is
>
> No, this is not the code.  There's a syntax error: inputStream and
> xmlInputStream are being confused here, xmlInputStream is not declared.
>
>
>
> >            xml = xml.trim();
> >            final InputStream inputStream = new
> > ByteArrayInputStream(xml.getBytes());
> >            final DocumentBuilderFactory dbf =
> > DocumentBuilderFactory.newInstance();
> >            final DocumentBuilder db = dbf.newDocumentBuilder();
> >            final Document doc = db.parse(xmlInputStream);
>
> > The block I'm trying to parse is below.  Can anyone see how it is mal-
> > formed?  Barring that, do you know a better way of parsing the string?
>
> Yes, there's a syntax error in the XML.  Construct a proper SSCCE to see it.

You mean a syntax error in the Java?  Ok, here it is ...

	public static com.myco.clearing.commons.xml.Node parse(String xml)
throws
			ParserConfigurationException, SAXException, IOException {
		xml = xml.trim();
		return parse(new ByteArrayInputStream(xml.getBytes()));
	}

	/**
	 *
	 * @param xml
	 * @return Parsed xml
	 * @throws XMLParseException
	 * @throws ParserConfigurationException
	 * @throws IOException
	 * @throws SAXException
	 */
	public static com.myco.clearing.commons.xml.Node parse(final
InputStream xmlInputStream)
			throws ParserConfigurationException,
			SAXException, IOException {

		final DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
		final DocumentBuilder db = dbf.newDocumentBuilder();
		final Document doc = db.parse(xmlInputStream);
		doc.getDocumentElement().normalize();

If you mean the XML, what is the XML syntax error or what tool can I
use to see it? - Dave

[toc] | [prev] | [next] | [standalone]


#9058

FromLew <lewbloch@gmail.com>
Date2011-10-20 14:06 -0700
Message-ID<17780527.1116.1319144796758.JavaMail.geo-discussion-forums@prib32>
In reply to#9043
DO NOT POST CODE USING TAB AS AN INDENTATION CHARACTER!

Bad!

laredotornado wrote:
> You mean a syntax error in the Java?  Ok, here it is ...
> 
> 	public static com.myco.clearing.commons.xml.Node parse(String xml)
> throws
> 			ParserConfigurationException, SAXException, IOException {
> 		xml = xml.trim();
> 		return parse(new ByteArrayInputStream(xml.getBytes()));

Encoding?

> 	}
> 
> 	/**
> 	 *
> 	 * @param xml

Where is 'xml'?

> 	 * @return Parsed xml

What is the definition of 'Parsed'?

> 	 * @throws XMLParseException

No, it doesn't.

> 	 * @throws ParserConfigurationException
> 	 * @throws IOException
> 	 * @throws SAXException
> 	 */
> 	public static com.myco.clearing.commons.xml.Node parse(final
> InputStream xmlInputStream)
> 			throws ParserConfigurationException,
> 			SAXException, IOException {
> 
> 		final DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> 		final DocumentBuilder db = dbf.newDocumentBuilder();
> 		final Document doc = db.parse(xmlInputStream);
> 		doc.getDocumentElement().normalize();
> 
> If you mean the XML, what is the XML syntax error or what tool can I
> use to see it? 

Is there a newline at the end of your XML?

GIYF:
<http://www.w3schools.com/xml/xml_validator.asp>

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#9045

FromDaniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Date2011-10-20 20:15 +0200
Message-ID<j7poi6$2c0$1@dont-email.me>
In reply to#9031
On 20/10/2011 17:41, laredotornado allegedly wrote:
> 		xml = xml.trim();
> 		final InputStream inputStream = new
> ByteArrayInputStream(xml.getBytes());
> 		final DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> 		final DocumentBuilder db = dbf.newDocumentBuilder();
> 		final Document doc = db.parse(xmlInputStream);

> 		final InputStream inputStream = new
> ByteArrayInputStream(xml.getBytes());

Don't do this.

Instead:

db.parse( new InputSource( new StringReader(xml) ) );

-- 
DF.
Determinism trumps correctness.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web