Hi!
I would like to know if there is a way to tell Castor to generate
XML files without any prefixes before elements and attributes?
In the first version of my application, I had only one XSD file
without any namespace. And the XML files generated by the Castor
marshaller were not containing any prefixes and namespaces of course.
But since I have splited my XSD file in multiple files with
different namespaces (no change in the data model itself), the XML files
generated by the Castor marshaller now contain multiple namespace prefixes
(see example below)!! The problem is that those XML files are read by
other non Java applications that do not recognize the namespace notation.
Before having to modify those applications, I would like to continue
generating the XML without the prefixes! But I did not find any way to do
that!!
Maybe I'm looking for something impossible or maybe it is so
obvious that I've missed it!!? ;-)
Here is an example (using Castor 0.9.5.3, Xerces 2.6.0, and JDK
1.4.2_02):
I have two XSD files from which I generate java files:
Imported.xsd : contains reusable data types
Test.xsd : imports the reusable data types
Imported.xsd:
============
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.mydomain.org/context/test/imported"
xmlns:imported="http://www.mydomain.org/context/test/imported" >
<xs:complexType name="ImportedType">
<xs:sequence>
<xs:element name="Field1" type="xs:string" minOccurs="1"
maxOccurs="1"/>
<xs:element name="Field2" type="xs:string" minOccurs="0"
maxOccurs="1"/>
<xs:element name="Field3" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Test.xsd:
========
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.mydomain.org/context/test"
xmlns:test="http://www.mydomain.org/context/test"
xmlns:imported="http://www.mydomain.org/context/test/imported" >
<xs:import
namespace="http://www.mydomain.org/context/test/imported"
schemaLocation="Imported.xsd" />
<xs:complexType name="MyTestType">
<xs:sequence>
<xs:element name="MyString" type="xs:string"
minOccurs="1" maxOccurs="1"/>
<xs:element name="MyImportedElement"
type="imported:ImportedType" minOccurs="0" maxOccurs="1"/>
<xs:element name="OtherImportedElement"
type="imported:ImportedType" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="RootElement" type="test:MyTestType" />
</xs:schema>
MyInstance1.xml
===============
- Following, is the XML file generated by Castor when marshalling an
instance of the java entities generated from the XSD.
No special options of the Marshaller class are used. It seams that
Castor dynamically generates multiple prefixes for the same namespace and
also use empty namespace!!? It is curious, but that's not the point of my
question!
<?xml version="1.0" encoding="UTF-8"?>
<RootElement xmlns="http://www.mydomain.org/context/test">
<MyString xmlns="">bla bla bla</MyString>
<ns1:MyImportedElement
xmlns:ns1="http://www.mydomain.org/context/test/imported">
<ns1:Field1>value1</ns1:Field1>
<ns1:Field2>value2</ns1:Field2>
<ns1:Field3>value3a</ns1:Field3>
<ns1:Field3>value3b</ns1:Field3>
</ns1:MyImportedElement>
<ns2:OtherImportedElementxmlns:ns2="http://www.mydomain.org/context/test/i
mported">
<ns2:Field1>value1</ns2:Field1>
</ns2:OtherImportedElement>
</RootElement>
MyInstance2.xml
===============
- Following, is the XML file generated by Castor when marshalling again
the same instance of the java entities
generated from the XSD, but this time specifying the prefixe to use for
each namespace
with the method setNamespaceMapping() of the Marshaller class.
Note that this XML is very good in most of the cases, but in my specific
case I don't want (and I don't need)
the namespaces and prefixes.
<?xml version="1.0" encoding="UTF-8"?>
<test:RootElement xmlns:test="http://www.mydomain.org/context/test"
xmlns:imported="http://www.mydomain.org/context/test/imported">
<test:MyString>bla bla bla</test:MyString>
<imported:MyImportedElement>
<imported:Field1>value1</imported:Field1>
<imported:Field2>value2</imported:Field2>
<imported:Field3>value3a</imported:Field3>
<imported:Field3>value3b</imported:Field3>
</imported:MyImportedElement>
<imported:OtherImportedElement>
<imported:Field1>value1</imported:Field1>
</imported:OtherImportedElement>
</test:RootElement>
MyInstance3.xml
===============
- And finally, the XML file I would expect to obtain, still using the same
instance of the java entities
generated from the XSD.
Are there any special options I can set in Castor or in thirdparty tools
used by Castor to obtain that result??
<?xml version="1.0" encoding="UTF-8"?>
<RootElement>
<MyString>bla bla bla</MyString>
<MyImportedElement>
<Field1>value1</Field1>
<Field2>value2</Field2>
<Field3>value3a</Field3>
<Field3>value3b</Field3>
</MyImportedElement>
<OtherImportedElement>
<Field1>value1</Field1>
</OtherImportedElement>
</RootElement>
Thank you very much for your help!!
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user