[jdom-interest] JDOM Issue #5 - DTD-aware Attribute output
Paul Libbrecht
paul at hoplahup.net
Thu Mar 22 13:27:58 PDT 2012
Hello list,
Rolf has been so kind to show me how JDOM issue #5 can be run.
So I ran the following snippet:
SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING);
Document doc = builder.build(new URL(args[0]));
Format speconly = Format.getRawFormat();
speconly.setSpecifiedAttributesOnly(true);
XMLOutputter xout = new XMLOutputter(speconly);
xout.output(doc, System.out);
which allows me to parse a JDOM source, make modifications (typically: refactorings), then output with almost no difference.
The big advantage to that is that the attributes that were not there... are simply not injected from the DTD.
This is enormous in some XML editing tradition which uses implied values a lot.
There's two BUT:
1) This currently fails if the validation fails and this is a big problem to me.
An example file would be the following:
http://svn.activemath.org/LeAM-calculus/LeAM_calculus/oqmath/contin.oqmath
which references a DTD nearby. This is a manually edited file.
Removing the validation, sadly disables the passing of attribute presence info, it seems.
Rolf, is there a way that the attribute presence info is passed but the validation is not stopped?
2) namespace declarations, which are kind of attributes, still resurface. They should be avoided if not present ideally. Doable?
The approach of Rolf is better than the one I had because mine was simply checking in the DTD if the attribute was provided by it and, if yes, removing its output while in Rolf's approach, an attribute that is there is output if... it was there, simply!
Thanks for comments.
paul
More information about the jdom-interest
mailing list