Hello,
I've recently started working with Castor-XML (0.9.3.19). I'm
having trouble with xsi:type and namespaces. My schemas involve
unbounded lists of children where the children derive from an abstract
class. So, in this sample schema we've got a list of AbstractNodes,
which in the instance document may take the form of concrete NodeA or
NodeB all of which is under a hypothetical namespace "http://testspace":
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://testspace"
version="1.0">
<xs:element name="root" type="Root" />
<xs:complexType name="Root">
<xs:sequence>
<xs:element name="node" type="AbstractNode" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AbstractNode" abstract="true">
<xs:attribute name="id" type="xs:int" />
</xs:complexType>
<xs:complexType name="NodeA">
<xs:complexContent>
<xs:extension base="AbstractNode">
<xs:attribute name="typeAAttrib" type="xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="NodeB">
<xs:complexContent>
<xs:extension base="AbstractNode">
<xs:attribute name="typeBAttrib" type="xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema
Original instance document:
<tst:root xmlns:tst="http://testspace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<node id="1" typeAAttrib="an attribute" xsi:type="tst:NodeA"/>
<node id="2" typeBAttrib="another attribute" xsi:type="tst:NodeB" />
</tst:root>
Using the SourceGenerator, I get a set of descriptors for the above
schema, and then unmarshal the instance document and marshal it again to
a new file.
Marshaller marshaller = new Marshaller(writer);
marshaller.setNamespaceMapping("tst","http://testspace");
marshaller.setNamespaceMapping("xsi","http://www.w3.org/2001/XMLSchema-instance");
marshaller.setRootElement("root");
marshaller.marshal(root);
This gives me a new document that looks like the following:
<tst:root xmlns:tst="http://testspace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tst:node id="1" typeAAttrib="an attribute" xsi:type="NodeA"/>
<tst:node id="2" typeBAttrib="another attribute" xsi:type="NodeB"/>
</tst:root>
The only important difference here is that the values within xsi:type do
not have the "tst:" namespace prefix and Xerces (1.4.3) fails to
validate the generated document because of the namespace conflict. It
comes back with a:
"General Schema Error: unresolved type : ,NodeA found in xsi:type
handling."
I'm not sure what I'm missing at this point, so any insight would be
appreciated.
Thanks for your time,
Josh Partlow
--
------------------------
Josh Partlow
[EMAIL PROTECTED]
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev