Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Problem w/ DocumentBuilder parse method (http://www.velocityreviews.com/forums/t955969-problem-w-documentbuilder-parse-method.html)

John L. 12-30-2012 07:30 PM

Problem w/ DocumentBuilder parse method
 
I'm pre-processing a file in an attempt to use the subject method, and receive the following error:

[Fatal Error] EXTRACT.TMP:51:23: The entity "nbsp" was referenced, but not declared.
Exception in thread "main" org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.
at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at Extract.CmdLine(Extract.java:144)
at Extract.main(Extract.java:79)

The pertinent portion of the file being parsed follows:

[45]<div>
[46]<input type="hidden" name="cx" value="partner-pub-5436175752152469:m8vqbgi2n
21" />
[47]<input type="hidden" name="cof" value="FORID:10" />
[48]<input type="hidden" name="ie" value="ISO-8859-1" />
[49]<input type="text" name="q" size="55" />
[50]<input type="submit" name="sa" value="PCM Search" />
[51] &nbsp; &nbsp; &nbsp; &nbsp; </div >

What is the required declaration syntax for &nbsp; to allow the file to be parsed?

Thanks in advance for your time and consideration.

Arne Vajhøj 12-30-2012 07:46 PM

Re: Problem w/ DocumentBuilder parse method
 
On 12/30/2012 2:30 PM, John L. wrote:
> I'm pre-processing a file in an attempt to use the subject method, and receive the following error:
>
> [Fatal Error] EXTRACT.TMP:51:23: The entity "nbsp" was referenced, but not declared.
> Exception in thread "main" org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.
> at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(Unknown Source)
> at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(Unknown Source)
> at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
> at Extract.CmdLine(Extract.java:144)
> at Extract.main(Extract.java:79)
>
> The pertinent portion of the file being parsed follows:
>
> [45]<div>
> [46]<input type="hidden" name="cx" value="partner-pub-5436175752152469:m8vqbgi2n
> 21" />
> [47]<input type="hidden" name="cof" value="FORID:10" />
> [48]<input type="hidden" name="ie" value="ISO-8859-1" />
> [49]<input type="text" name="q" size="55" />
> [50]<input type="submit" name="sa" value="PCM Search" />
> [51] &nbsp; &nbsp; &nbsp; &nbsp; </div >
>
> What is the required declaration syntax for &nbsp; to allow the file to be parsed?


Entities should be defined in the DTD.

The above looks like XHTML, so maybe it will work if you add a proper
DOCTYPE at the top (I think XHTML DTD defines nbsp)..

Arne



Roedy Green 12-31-2012 10:09 PM

Re: Problem w/ DocumentBuilder parse method
 
On Sun, 30 Dec 2012 11:30:24 -0800 (PST), "John L."
<johnlarew@sbcglobal.net> wrote, quoted or indirectly quoted someone
who said :

>The entity "nbsp" was referenced, but not declared.


XML supports just a tiny handful of entities and &nbsp; is not one of
them. You are expected to use UTF-8 encodings or formally declare the
meaning of your entities in a DTD.

see http://mindprod.com/jgloss/xml.html#AWKWARD
--
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish
as couch potatoes who hire others to go to the gym for them.

Stanimir Stamenkov 01-01-2013 12:17 AM

Re: Problem w/ DocumentBuilder parse method
 
Sun, 30 Dec 2012 11:30:24 -0800 (PST), /John L./:

> I'm pre-processing a file in an attempt to use the subject method, and receive the following error:
>
> [Fatal Error] EXTRACT.TMP:51:23: The entity "nbsp" was referenced, but not declared.
> [...]
> What is the required declaration syntax for &nbsp; to allow the file to be parsed?


As Arne Vajhøj points in another reply, there should be an XHTML
DOCTYPE declaration at the beginning of the document. Browsers
usually don't have problem processing XHTML containing entity
references from the XHTML DTD, even without DOCTYPE declaration,
because either:

1. The document is served as text/html, which is not processed as
XML at all, or;

2. Browsers have and refer to the XHTML DTD locally and are
automatically associating it automatically based on content-type:
application/xhtml+xml, or xmlns="http://www.w3.org/1999/xhtml" on
the root html element.

If the document you're trying to parse is at your control, you could:

1. Add the XHTML DOCTYPE declaration manually:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

or even:

<!DOCTYPE html
SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

You may still want to supply EntityResolver [1] to serve this
DTD from a local resource;

2. Add a DOCTYPE with a local subset containing just the necessary
entity declarations, like:

<!DOCTYPE html [
<!ENTITY nbsp " ">
]>

If you're parsing documents which don't have DOCTYPE declaration and
are not in your control, you may supply EntityResolver2
implementation which defines additional interface for just that purpose:

http://docs.oracle.com/javase/6/docs...lang.String%29

[1]
http://docs.oracle.com/javase/6/docs...ityResolver%29

--
Stanimir


All times are GMT. The time now is 03:33 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57