Have you tried loading the type as an xmlobject, getting the value of
the namespace, and casting to the correct type?
ie //pcode, please excuse incorrectness

if(xmlobject.getNamespace() == namespace1)
  type = (typeDocument)xmlobject;

-or-
you could change the namespace using the xmlcursor or DOM apis before
creating the type. In other words:
XmlObject xo  = XmlObject.Factory.parse(instance);
XmlCursor xc = XmlObject.newCursor();
xc.changeNS();
and then assign to the most recent NS, type

If ns replacement is a valid solution for you, you could always just
try something like:
(yes, way more hackish)
String goodInstance = xo.xmlText().replaceAll("oldNS", "newNs");
TypeDocument t = TypeDocument.factory.parse(goodInstance);

Please let us know if any of these solutions works for you.

-jacob danner

-------------------
sent from my nokia 9500

On 3/28/07, Matthieu Riou <[EMAIL PROTECTED]> wrote:
Hi,

I'm having some difficulties to support the reading of an XML instance
document that could belong to two different target namespaces. I'm using
XMLBeans to compile a schema and then read and browse instances using the
generated Java data structures.

Originally, my schema was in a first namespace:
http://ode.fivesight.com/schemas/2006/06/27/dd. So my schema header
declaration was something like:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
           targetNamespace="http://ode.fivesight.com/schemas/2006/06/27/dd";
....

And in my xsdconfig I had the following:

  <xb:namespace uri="http://ode.fivesight.com/schemas/2006/06/27/dd";>
    <xb:package>org.apache.ode.bpel.dd</xb:package>
  </xb:namespace>

Now I want to update that target namespace to
http://www.apache.org/ode/schemas/dd/2007/03 while still maintaining
backward compatibility with older documents. So if someone gives me a
document that looks like:

<deploy xmlns="http://ode.fivesight.com/schemas/2006/06/27/dd"; ...

I would like XMLBeans to either ignore this namespace and replace it with
the new one or generate exactly the same data structure as with the new
namespace so I don't need to change my whole java code.

I've tried different approaches, the first one was to declare the two
namespaces in my xsdconfig:

  <xb:namespace uri="http://ode.fivesight.com/schemas/2006/06/27/dd";>
    <xb:package>org.apache.ode.bpel.dd</xb:package>
  </xb:namespace>
  <xb:namespace uri="http://www.apache.org/ode/schemas/dd/2007/03";>
    <xb:package>org.apache.ode.bpel.dd</xb:package>
  </xb:namespace>

The gotcha is that my schema can only have one target namespace anyway so
that doesn't quite fly. My second try was to do:

                XmlOptions options = new XmlOptions();
                HashMap otherNs = new HashMap();

otherNs.put("http://ode.fivesight.com/schemas/2006/06/27/dd";,
"http://www.apache.org/ode/schemas/dd/2007/03";);
                options.setLoadSubstituteNamespaces(otherNs);
                _dd = DeployDocument.Factory.parse(ddLocation);

When I load the instance. That didn't work either, in both cases XMLBeans
complains with:

org.apache.xmlbeans.XmlException: /home/dusty/Dev/Tools/Platform/apache-
tomcat-5.5.17/webapps/ode/WEB-INF/processes/DynPartner/deploy.xml:0: error:
The document is not a [EMAIL PROTECTED]://www.apache.org/ode/schemas/dd/2007/03:
document element namespace mismatch expected "
http://www.apache.org/ode/schemas/dd/2007/03"; got "
http://ode.fivesight.com/schemas/2006/06/27/dd";.

Is there any solution to my problem?

Thanks,
Matthieu

Reply via email to