Problem w/ DocumentBuilder parse method

Discussion in 'Java' started by John L., Dec 30, 2012.

  1. John L.

    John L. Guest

    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.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.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.
    John L., Dec 30, 2012
    #1
    1. Advertising

  2. John L.

    Arne Vajhøj Guest

    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.DOMParser.parse(Unknown Source)
    > at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.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
    Arne Vajhøj, Dec 30, 2012
    #2
    1. Advertising

  3. John L.

    Roedy Green Guest

    On Sun, 30 Dec 2012 11:30:24 -0800 (PST), "John L."
    <> 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.
    Roedy Green, Dec 31, 2012
    #3
  4. 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/doc...nalSubset(java.lang.String, java.lang.String)

    [1]
    http://docs.oracle.com/javase/6/doc...setEntityResolver(org.xml.sax.EntityResolver)

    --
    Stanimir
    Stanimir Stamenkov, Jan 1, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    7,949
  2. David
    Replies:
    0
    Views:
    562
    David
    May 27, 2004
  3. David
    Replies:
    1
    Views:
    2,134
    Filip Larsen
    Jun 6, 2004
  4. Replies:
    1
    Views:
    731
    Esmond Pitt
    Mar 27, 2005
  5. BeGreen
    Replies:
    14
    Views:
    2,381
    BeGreen
    Aug 14, 2006
Loading...

Share This Page