You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Don Stewart <Do...@corizon.com> on 2005/06/20 18:26:32 UTC

Namespace question

Hi,
 
I'm getting an issue with namespaces that I cannot figure out. My schema
(read customers) defines a namespace:-
 
xmlns:dt="urn:bla/blabla/Assurance"

 

Without any XmlOptions I get :-

<ass:Parent>

    <ass:A/>

    <ass:Foo xmlns:ass="urn:bla/blabla/Assurance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ass:DetailedBla">

    </ass:Bla>

    <ass:B/>

</ass:Parent>

 

When I generate I set the XmlOptions with :-

        XmlOptions xmlOptions = new XmlOptions();
        xmlOptions.setSavePrettyPrintIndent(4);
        xmlOptions.setSavePrettyPrintOffset(4);
        xmlOptions.setSavePrettyPrint();
        xmlOptions.setLoadLineNumbers();
        Map namespaceMap = new HashMap();
        namespaceMap.put("dt", "urn:bla/blabla/Assurance");
        xmlOptions.setLoadSubstituteNamespaces(namespaceMap);
        xmlOptions.setSaveImplicitNamespaces(namespaceMap);

 

The prefix changes to <dt:Foo>

All except one inner block that starts as <ass: where the namespace is
redefined to be the same.

Now what differs in the generation is that Foo is a derived type so its
actually a DetailedFoo which I create using the
DetailedFoo.Factory.newInstance(xmlOptions) method passing in the same
XmlOptions as above i.e. with the namespace mapping that worked for all
the other tags. I then use a Parent.setFoo() method to add it to the
Parent XmlObject. This is because Parent has only a setFoo() and not a
Parent.setDetailedFoo().

Can anyone tell me why I end up with :-

<dt:Parent>

    <dt:A/>

    <ass:Foo xmlns:ass="urn:bla/blabla/Assurance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ass:DetailedFoo">

    </ass:Foo>

    <dt:B/>

</dt:Parent>

 

I realise that the redefinition of the element is causing it to be
redined but why is this sub-element not subject to remapping the same as
the other level. Anyone shed some light on this for me ??

 

Many Thanks

 

Don


insert foreign schema element

Posted by argyn <ar...@cox.net>.
I have a "my-schema" with one of the element defined like this:
=======
    <xs:element name="Content" type="ContentType"/>
    <xs:complexType name="ContentType" mixed="true">
        <xs:sequence>
            <xs:any namespace="##any" processContents="lax" 
minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:anyAttribute namespace="##any" processContents="lax"/>
    </xs:complexType>
=======
The idea is that Content element can contain any elements from other 
schemas, or simply some text or data.

here's a xml fragment of the document:
=======
<?xml version="1.0" encoding="UTF-8"?>
<Request
      xmlns="my-schema"
      xmlns:md="foreign-schema"
 >

...[skip this]...

        <Content>
            <md:record>
                <md:patient_info>
                    <md:name>XYZ</md:name>
                    <md:age>60</md:age>
                    <md:sex>male</md:sex>
                    <md:health_insurance>123456</md:health_insurance>
                </md:patient_info>
            </md:record>
        </Content>
=======

I'm having trouble constructing this document. If I use 
cursor.insertChars() or setTextValue() then the document looks like this:

=======
    <Content><![CDATA[<md:record>
  <md:patient_info>
    <md:name>XYZ</md:name>
    <md:age>60</md:age>
    <md:sex>male</md:sex>
--- etc
=======

i.e. XmlBeans adds <![CDATA[. How to insert the foreign elements into 
the XML with XMLBeans?

thanks,
argyn


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org