xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cezar Andrei" <ce...@bea.com>
Subject RE: anyType and namespaces
Date Tue, 16 Nov 2004 16:02:23 GMT
Stefan,

Have you tried saving the document with setSaveAggressiveNamespaces()
XmlOption ?


-----Original Message-----
From: Stefan Armbruster [mailto:stefan@armbruster-it.de] 
Sent: Monday, November 15, 2004 4:53 AM
To: xmlbeans-user@xml.apache.org
Subject: anyType and namespaces

Hi,

I've got some problems with namespace declarations when using
"xs:anyType". In order to make the situation as clear as possible, I got
a stripped down example:
----- schema ------
<xs:schema targetNamespace="http://mysample.org/sample1"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">

<xs:element name="product">
<xs:complexType>
        <xs:sequence>
            <xs:element name="name" minOccurs="1" maxOccurs="1"
type="xs:string"/>
            <xs:element name="property" minOccurs="1" maxOccurs="1"
type="xs:anyType"/>
        </xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="color">
  <xs:restriction base="xs:string">
    <xs:enumeration value="red"/>
    <xs:enumeration value="green"/>
    <xs:enumeration value="blue"/>
  </xs:restriction>
</xs:simpleType>

</xs:schema>
----- END: schema -----

Among others, the color type might be used for the element property.
Using the following java code, a XML document is printed,

----- java --------
ProductDocument pd = ProductDocument.Factory.newInstance();
ProductDocument.Product p =
ProductDocument.Product.Factory.newInstance();
p.setName("Product 1");

Color prop = Color.Factory.newInstance();
prop.setStringValue("red");
p.setProperty(prop);

pd.setProduct(p);
XmlOptions options = new XmlOptions();
options.setSavePrettyPrint();
options.setUseDefaultNamespace();
options.setSaveAggresiveNamespaces();
pd.save(System.out, options);
------ END: java----

---- console-output ----
<?xml version="1.0" encoding="UTF-8"?>
<product xmlns="http://mysample.org/sample1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <name>Product 1</name>
  <sam:property xsi:type="sam:color"
xmlns:sam="http://mysample.org/sample1">red</sam:property>
</product>
---- END: console-output ----

Here comes the trouble: "property" has a namespace "sam". Since color is
defined in the same namespace like product, the usage of namespaces is
not necessary. I'd like to to see this output:

<?xml version="1.0" encoding="UTF-8"?>
<product xmlns="http://mysample.org/sample1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <name>Product 1</name>
  <property xsi:type="color">red</property>
</product>

Is there any way to achieve this? I played around using XmlOptions -
without success.

TIA,
Stefan


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



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


Mime
View raw message