users@jaxb.java.net

Namespace problems with imported schemas

From: Siedow, Ralf <Ralf.Siedow_at_telekom.de>
Date: Thu, 03 Apr 2003 10:41:38 +0200

Hello,

I'm using Magginson's XMLWriter with classes generated from a schema which imports another schema.

My Schema (NEW_MODIFY.xsd):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="test:rfc2" xmlns:rfc="urn:test:rfc" xmlns="urn:test:rfc2" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:import namespace="urn:test:rfc" schemaLocation="MODIFY.xsd"/>
        <xs:element name="NEW_MODIFY">
                <xs:annotation>
                        <xs:documentation/>
                </xs:annotation>
                <xs:complexType>
                        <xs:sequence>
                                <xs:element name="BODY" type="rfc:BODY_IN"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
</xs:schema>

What I'd like to do is to read a test.xml which validates against the imported schema and take the BODY_IN (a substructure) and hang it into my new xml at the BODY element (testout.xml) which validates against my own schema (NEW_MODIFY.xsd).

This gives me the following result (testout.xml):
<?xml version="1.0" standalone="yes"?>
<NEW_MODIFY xsi:noNamespaceSchemaLocation="NEW_MODIFY.xsd" xmlns="urn:test:rfc2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <BODY>
                <rfc:PARTNER xmlns:rfc="urn:test:rfc">789798</rfc:PARTNER>
                <rfc:COUNTRY xmlns:rfc="urn:test:rfc">DE</rfc:COUNTRY>
        </BODY>
</NEW_MODIFY>

How can I get rid of the multiple xmlns:rfc namespace settings and set it once in NEW_MODIFY (xmlns:rfc="urn:test:rfc")?

My code that should but doesn't do the job ;-)
        YKSGPV20MODIFY root = (YKSGPV20MODIFY) readJaxb("test.xml");

        ObjectFactory objFac = new ObjectFactory();
                NEWMODIFY new_root = objFac.createNEWMODIFY();
                new_root.setBODY(root.getBODYIN());

        JAXBContext jc = JAXBContext.newInstance("test:rfc2");

        // Setup JAXB to unmarshal
        XMLWriter writer = new XMLWriter();
                writer.setPrefix("urn:test:rfc", "rfc");
                writer.setPrefix("urn:test:rfc2", "rfc2");

        Marshaller m = jc.createMarshaller();
                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
                m.setProperty(
                        Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION,
                        xsd);
        m.marshal(new_root, writer);


Newbie question: Any hints about documentation describing the urn:* -Syntax (I guess there is one)? Why does xjb create a test/rfc directory and not urn/test/rfc?
URN=Uniform Resource Name???

Thanks a lot,
        Ralf