[jdom-interest] Subclassing XMLOutputter WAS: SAXBuilder inclusion
of default attributes
Jason Hunter
jhunter at servlets.com
Wed Jan 21 10:37:59 PST 2004
I'm glad to see Xerces supports this now. Do any other parsers? It's
an old TODO item to decorate the Attribute with this metadata so that we
can have more effective round tripping.
One idea I have is to enhance the builder to do the Right Thing for
Xerces to get this information, prob using reflection probably to avoid
any class cast exceptions if Xerces isn't present. As other parsers
support this feature, we can add support for them there as well.
This does make JDOM's behavior depend a bit on the parser, but since
users can choose their parser, if this feature is important to them they
can make sure to choose Xerces.
Then we can standardize the XMLOutputter behavior to use the Attribute
metadata as appropriate.
-jh-
Per Norrman wrote:
> Hi,
>
> I was playing around with the latest Xerces (2.6) and realized that
> it is quite easy to capture wether an attribute is defined implicitly
> through the schema or explicitly in the source xml. You can (hopefully)
> get the general idea from the example attached (note: this example is
> not
> complete, it depends on a patched version in XMLOutputter).
>
> However, my experiment higlighted a problem with XMLOutputter. My idea
> was
> to extend org.jdom.Attribute and record for each attribute occurrance if
> it was schema defined, and then, in XMLOutputter just skip printing
> those
> attributes.
>
> I can override XMLOutputter#printAttributes, but I cannot call
> XMLOutputter#printNamespace, since it is private, forcing me to
> duplicate this
> effort. This particular problem could be fixed if we 1) extract the bulk
> of the
> iteration loop into a new method, printAttribute(Writer, Attribute,
> XMLOutputter.Namespacestack), or 2) make printNamespace protected.
>
> Ideas?
>
> /pmn
>
>
>
>>-----Ursprungligt meddelande-----
>>Från: jdom-interest-admin at jdom.org
>>[mailto:jdom-interest-admin at jdom.org] För Ing. Terenzio Berni
>>Skickat: den 20 januari 2004 11:53
>>Till: jdom-interest at jdom.org
>>Ämne: R: [jdom-interest] SAXBuilder inclusion of default attributes
>>
>>
>>Apparently I have the same problem Harry Evans reported.
>>I've tried his solution (setting up an entity resolver):
>>
>>SAXBuilder builder = new SAXBuilder();
>>builder.setEntityResolver(new EntityResolver() {
>> public InputSource resolveEntity(String publicId, String
>>systemId) {
>> return new InputSource(new ByteArrayInputStream(new byte[0]));
>> }
>>});
>>
>>after this I set up the XSD schema validation with these instructions:
>>
>>saxBuilder.setFeature("http://apache.org/xml/features/validati
>>on/schema",
>>true);
>>
>>saxBuilder.setFeature("http://xml.org/sax/features/namespaces",true);
>>
>>saxBuilder.setProperty("http://apache.org/xml/properties/schem
>>a/external-sch
>>emaLocation","urn:hl7-org:v2xml file:///C:/HL7/xsd/messages.xsd");
>>
>>but when I try to create the JDOMDocument via:
>>
>>Document document = builder.build(inputstream);
>>
>>I get a JDOMParseException (here reported)
>>
>>org.jdom.input.JDOMParseException: Error on line -1:
>>Premature end of file.
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:381)
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:684)
>> at HL7InOutWithJDOM.main(HL7InOutWithJDOM.java:49)
>>Caused by: org.xml.sax.SAXParseException: Premature end of file.
>> at
>>org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
>> ... 2 more
>>Caused by: org.xml.sax.SAXParseException: Premature end of file.
>> at
>>org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:684)
>> at HL7InOutWithJDOM.main(HL7InOutWithJDOM.java:49)
>>Caused by: org.xml.sax.SAXParseException: Premature end of file.
>> at
>>org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
>> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:684)
>> at HL7InOutWithJDOM.main(HL7InOutWithJDOM.java:49)
>>
>>Regards,
>>Terenzio Berni
>>
>>_______________________________________________
>>To control your jdom-interest membership:
>>http://lists.denveronline.net/mailman/options/jdom-interest/yo
>
> uraddr at yourhost.com
More information about the jdom-interest
mailing list