[jdom-interest] Special XMLOutputter which omits namespaces?
Guillaume Berche
guillaume.berche at eloquant.com
Tue May 18 06:08:14 PDT 2004
Hello,
I've been pretty happy with JDom b8 except for the special need that I have
to output some XML fragment without including the namespace prefixes in each
element. The use-case for this is that I obtain a JDom tree from an XML
document using Xerces with schema validation on. I obtain a valid JDom tree
with the proper namespaces. I then want to dump a part of that tree without
specifying the namespace of each element.
I had looked at various threads on this list a while ago and concluded the
best way for me to do this was to create a new "NoNameSpaceXMLOutputter"
based on the org.jdom.output.XMLOutputter and just modify the behavior of
the private "void printNamespace(Namespace ns, Writer out,
NamespaceStack namespaces)" method, to have it return immediately, and not
insert namespaces element prefixes.
I wonder whether as part of the beta 10, there is better way of using JDom
than duplicating the XMLOutputter code. I briefly looked at the new
org.jdom.output.Format class but could not find something corresponding to
my need.
I realize this may be a specific need and may not justify extension in the
Format mechanism for the 1.0, but it may be interesting to support wider
subclassing of the org.jdom.output.XMLOutputter class by having some of its
methods now be exposed as "protected" instead of "private". So for the final
1.0, I'd then advocate for the "void printNamespace(Namespace ns, Writer
out, NamespaceStack namespaces)" method, so my NoNameSpaceXMLOutputter class
would simply override this method instead of having to duplicate the whole
class.
Thanks for your help and for this great library!
Regards,
Guillaume.
More information about the jdom-interest
mailing list