Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: org.xml.sax.SAXParseException: Premature end of file Date: Thu, 20 Oct 2011 10:04:03 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <22aef44f-90f0-4fe4-a20e-64f336e4c1b3@g25g2000yqh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 20 Oct 2011 17:04:05 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="12123"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OKJ3xz5uJ6m9DYeF2RpqFR3ai7306mvY=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 In-Reply-To: <22aef44f-90f0-4fe4-a20e-64f336e4c1b3@g25g2000yqh.googlegroups.com> Cancel-Lock: sha1:aa0sR2fURqW98MTNomqj9tPRwJE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9038 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.