Search code examples
namespacesprefixjdom

How can I force a JDOM XMLOutputter to write namespace prefixes on all elements?


I'm writing XML that will be consumed by the Windows WebFolder (for mounting a WebDAV volume). WebFolder requires that all elements have a prefix on them, so instead of this:

<one xmlns="DAV:">
    <two />
    <three />
</one>

I need to do this:

<D:one xmlns:D="DAV:">
    <D:two />
    <D:three />
</D:one>

This is ugly and should be unnecessary, but it's Microsoft, and they do it their way, so whatever. The question is, how can I tell JDOM to write the XML this way?


Solution

  • Found the answer: the JDOM Namespace class has a 3-arg version that takes a local name, namespace, and prefix. If you use that version with the desired prefix, it works as desired. Sorry for the dumb question, maybe this will help somebody else.