You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Maarten Bosteels <mb...@gmail.com> on 2007/07/27 16:02:57 UTC

change namespace of generated document

Hello,

My question is related to
http://www.mail-archive.com/user@xmlbeans.apache.org/msg02086.html

Suppose I want to support two versions of the same schema, but I want to use
only one set of classes.
The two schema's are almost identical, and every document that is valid
according to easypo-v1.xsd
will be valid according to easypo-v2.xsd

I already found the solution for incoming documents in the thread mentioned
above.

    Map<String,String> substitutes = new HashMap<String, String>();
    // xmlbeans will treat namespace "http://openuri.org/easypo/v1" as a
substitute for "http://openuri.org/easypo/v2"
    substitutes.put("http://openuri.org/easypo/v2", "
http://openuri.org/easypo/v1");
    XmlOptions options = new XmlOptions();
    options.setLoadSubstituteNamespaces(substitutes);
    try {
      XmlObject doc = XmlObject.Factory.parse(xml, options);
      ...

But I wonder how I can change the namespace used in documents created via
PurchaseOrderDocument.Factory.newInstance();

Thus, I let xmlbeans generate classes based on easypo-v2.xsd
but if the incoming request uses easypo-v1.xsd I want to generate an answer
that uses easypo-v1.xsd
although the document would be created with classes generated for
easypo-v2.xsd

One solution would be to do string replacements in the resulting document
but I hope there are better solutions.

Thanks in advance,
Maarten