Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

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

Ing. Terenzio Berni

2004-01-20

Replies:

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


-----Messaggio originale-----
Da: jdom-interest-admin@(protected)
[mailto:jdom-interest-admin@(protected)
Inviato: marted? 20 gennaio 2004 5.43
A: Elliotte Rusty Harold
Cc: jdom-interest@(protected)
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@(protected)
t.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.