You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Paul Hepworth <Pa...@detica.com> on 2008/06/10 15:03:06 UTC

Namespace Consolidation

Hi all,
 
I'm having trouble keeping my namespace declarations under control and
was wondering whether there was any way to consolidate them all into the
root element in my XML (setSaveAggressiveNamespaces(...) doesn't work)?
 
I have quite a complex schema, and certain templates stored in the DB
for the different types of complex types. These templates are retrieved
as a String (CLOB), and parsed using the MyObjectType.Factory.parse(...)
method. At this point, and quite rightly, the appropriate namespaces are
added.
 
Throughout the app and via numerous method calls and user interaction, I
build up a large XML document. However, the result of which is that I
have a mess of XML (albeit perfectly valid). 
There are numerous re-declarations of namespaces, sometimes as a default
namespace, and sometimes with a specific prefix. Although the XML is
perfectly valid, it's far from standard, and all the namespace
declarations end up taking up about as much as the actual data itself.
 
So I end up with something along the lines of:
<bobns:a xmlns:bobns="http://namespace.of.bob">
    <b xmlns="http://namespace.of.bob">
        <c>Bob</c>
    </b>
    <bobns:d xmlns:bobns="http://namespace.of.bob">
        <bobns:e>Fred</bobns:e>
    </bobns:d>
</bobns:a>
 
What I'm after is to consolidate all the namespaces into the root
element, and have all the rest of the xml to be qualified with their
appropriate namespaces. Something like this:
<bobns:a xmlns:bobns="http://namespace.of.bob">
    <bobns:b>
        <bobns:c>Bob</bobns:c>
    </bobns:b>
    <bobns:d>
        <bobns:e>Fred</bobns:e>
    </bobns:d>
</bobns:a>
 
I've been experimenting with XMLOptions, and
setSaveAggressiveNamespaces(...) etc, but nothing is giving me the
result I need.
The closest I've come is to use setSaveImplicitNamespaces(...) which
strips all the namespace declarations, and leaves the XML with the
desired tidy namespace prefixes... only there are no namespace
declarations and so the XML is ultimately invalid. It gives me something
like this, which without the declaration of bobns is invalid:
<bobns:a>
    <bobns:b>
        <bobns:c>Bob</bobns:c>
    </bobns:b>
    <bobns:d>
        <bobns:e>Fred</bobns:e>
    </bobns:d>
</bobns:a>
 
Can anyone suggest the best approach for this?
 
Thanks
Paul



This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory.  The contents of this email may relate to dealings with other companies within the Detica Group plc group of companies.

Detica Limited is registered in England under No: 1337451.

Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.