|
Hi to All,
Does anyone know how to remove
built-in Castor namespace prefixes like ns1, ns2, .... from generated
(marshalled) xml file? When does Castor attach this string to xml
elements/attributes. I noticed that prefixes do not exist when mapping is
simple. Using inheritance and handlers in mapping does cause my problem....
I have experimented a lot with calling methods on marshaller (ie.
setNamespaceMapping(null, uri) - no effects).
Thank You very much for _ANY_ answers. Greetings,
Przemek.
===== My files:
------------
Output xml file with example of unwanted "ns1"
prefixes:
------------
<?xml version="1.0"
encoding="UTF-8"?> <myclass ns1:id="1" xmlns="http://somenamespace.com/namespace" xmlns:ns1="http://somenamespace.com/namespace"> <attribute> <a>aValue</a> <b>bValue</b> </attribute> <attributeRef> <c>NameRef1</c> <item> <myclass ns1:id="2"> <attribute> <a>aValue2</a> <b>bValue2</b> </attribute> <attributeRef> <c>NameRef2</c> <item> <myclass ns1:id="3"> <attribute> <a>aValue3</a> <b>bValue3</b> </attribute> </myclass> </item> </attributeRef> </myclass> </item> </attributeRef> </myclass> --------------
Mapping file (it uses features like inheritance
or handler):
---------------
<mapping
xmlns="http://somenamespace.com/namespace" xmlns:co="http://java.sun.com/products/oss/xml/Common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://somenamespace.com/namespace c:\somedir\someschema.xsd"> <class name="MySpecificClass"
identity="id" auto_complete="false"
extends="MyClass">
<map-to xml="myspecificclass" ns-uri="http://somenamespace.com/namespace"/> <field name="specificField" type="string"> <bind-xml name="specificField" node="element"/> </field> </class> <class name="MyClass"
identity="id" auto-complete="false">
<map-to xml="myclass" ns-uri="http://somenamespace.com/namespace"/> <field name="id" type="string"> <bind-xml name="id" node="attribute"/> </field> <field name="attributes" collection="map" type="org.exolab.castor.mapping.MapItem"> <bind-xml name="attribute"> <class name="org.exolab.castor.mapping.MapItem"> <field name="key" type="string"> <bind-xml name="a" node="element"/> </field> <field name="value" type="string"> <bind-xml name="b" node="element"/> </field> </class> </bind-xml> </field> <field name="attributeRefs" collection="map" type="org.exolab.castor.mapping.MapItem"> <bind-xml name="attributeRef"> <class name="org.exolab.castor.mapping.MapItem"> <field name="key" type="string"> <bind-xml name="c" node="element"/> </field> <field name="value" type="MyClassChoice" handler="MyClassChoiceHandler"> <bind-xml name="item" node="element"/> </field> </class> </bind-xml> </field> </class> <class name="MyClassChoice"
auto-complete="false">
<map-to xml="item"/> <field name="myclass" type="MyClass"> <bind-xml name="myclass" node="element"/> </field> <field name="myrefclass" type="MyClass"> <bind-xml name="id_ref" reference="true" node="attribute"/> </field> </class> </mapping>
-----------
Dumb handler:
-----------
public class MyClassChoiceHandler extends
GeneralizedFieldHandler {
public Object
convertUponGet(Object value) {
MyClassChoice choice = new MyClassChoice(); MyClass myClass = (MyClass) value; choice.setMyclass(myClass); return
choice;
} public Object
convertUponSet(Object value) {
MyClassChoice choice = (MyClassChoice) value; if
(choice.getMyrefclass() != null)
{
return choice.getMyrefclass(); } return choice.getMyclass(); } public Class getFieldType()
{
return MyClassChoice.class; } } -----------------
Content of main() method:
----------------
Writer buffer = new StringWriter();
Marshaller marshaller = new Marshaller(buffer); marshaller.setMapping(mapping); marshaller.setValidation(true); marshaller.setMarshalExtendedType(true); marshaller.marshal(obj);
-----------------------------
|
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
