[jdom-interest] Subclassing XMLOutputter WAS: SAXBuilder inclusion of default attributes
Per Norrman
pernorrman at telia.com
Tue Jan 20 08:48:06 PST 2004
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestSchema.java
Type: application/octet-stream
Size: 4313 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20040120/6064b22e/TestSchema.obj
More information about the jdom-interest
mailing list