Hello,

I have created a mapping file to map an existing XSD to existing Java classes. 
Unmarshalling the XML seems to run fine, but I am having trouble getting valid
XML when marshalling the objects.  I am trying to marshal an object and create
XML with namespace prefixes for the elements and no prefixes for the
attributes, as defined by the XSD I'm working with, like this:

<pre:rootElement
    xmlns="http://my.name.space";
    xmlns:pre="http://my.name.space";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://my.name.space http://my.xsd.location";
    attribute1="valueA"
    attribute2="valueB">
  <pre:element1 attribute1="valueA"
                attribute2="valueB">elementValue</pre:element1>
</pre:rootElement>

In my mapping file, the attributes are mapped as "attribute1" and elements are
mapped as "pre:element1".  I have tried several different variations in my
marshalling code, but the three results that I keep getting are (all of which
are invalid according to the XSD):

1. Elements and attribute both have my namespace prefix.
2. Elements and attribute both do not have any prefixes.
3. Elements have my namespace prefix and attributes are given an "ns1" prefix
for a Castor namespace.

I modeled my mapping file after the example in the XML validation section in the
Castor documentation and the namespaces look like this:

<mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xmlns="http://castor.exolab.org/";
         xmlns:pre="http://my.name.space";
         xsi:schemaLocation="http://castor.exolab.org/ mapping.xsd">

I have been trying different variations on the above header and of this
marshalling code, with no luck:

marshaller.setNamespaceMapping("", "http://my.name.space";);
marshaller.setNamespaceMapping("pre", "http://my.name.space";);
marshaller.setSchemaLocation("http://my.name.space http://my.xsd.location";);
marshaller.marshal(valueObject);

Does anyone know the correct way to get my attributes marshalled without a
namespace prefix and my elements marshalled with my namespace prefix?  (Along
with the correct namespace declarations in my XML.)

Thank you,
Mike

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to