R: [jdom-interest] SAXBuilder inclusion of default attributes

Ing. Terenzio Berni tberni at dianoema.it
Tue Jan 20 02:41:28 PST 2004


Apparently I have the same problem of Harry Evans.
I've tried his peace of code:


-----Messaggio originale-----
Da: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]Per conto di Harry Evans
Inviato: martedì 20 gennaio 2004 5.43
A: Elliotte Rusty Harold
Cc: jdom-interest at jdom.org
Oggetto: Re: [jdom-interest] SAXBuilder inclusion of default attributes


Thanks for the tip.  Unfortunately, it seems that neither xerces nor
crimson allow this flag to be set.  I get the following when I try to
set the feature value to false:
org.jdom.JDOMException:
http://xml.org/sax/features/external-general-entities feature not
supported for SAX driver org.apache.xerces.parsers.SAXParser
    at org.jdom.input.SAXBuilder.internalSetFeature(SAXBuilder.java:643)
    at
org.jdom.input.SAXBuilder.setFeaturesAndProperties(SAXBuilder.java:585)
    at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:467)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:341)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:684)
<etc>

However, armed with this information I was able to find a web resource
that talked about this
(http://www.topxml.com/xml/articles/sax2/default.asp), and I came up
with the following (which seems to work great):

SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new EntityResolver() {
    public InputSource resolveEntity(String publicId, String systemId) {
        return new InputSource(new ByteArrayInputStream(new byte[0]));
    }
});

Thanks for the information.  I would have never found this without
knowing it was a feature and what the name was.

Harry Evans

Elliotte Rusty Harold wrote:

> At 6:32 PM -0800 1/19/04, Harry Evans wrote:
>
>> I am working with a third party data source, that submits xml to me.
>> The DTD for this submission contains several elements that have
>> attributes with default values, ie if certain attributes for an
>> element are omitted, they have a default value, as defined by the DTD.
>>
>> I am doing some manipulation of this file and then sending it on to a
>> new destination.  However, when I use SAXBuilder to build the
>> document (even with validation off), it explicitly includes the
>> default values for omitted attributes in the Document.
>>
>
> You need to turn off not only validation but also external entity
> resolution. I think the relevant feature is
> http://xml.org/sax/features/external-general-entities

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list