You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by ext2 <xu...@tongtech.com> on 2010/12/13 08:02:20 UTC
DOMSource cannot be loaded as SDO correctly
Hi:
If I convert a xml to sdo which stand for a xsd's global element;
The Tuscany SDO always ask for me to using string , and cannot using
DOMSource.
If I using DOMSource, the Tuscany cannot aware to the xml element's type, so
the converted SDO's type is not correct, it will always be ANYTYPE;
This means I must convert DOM to String first, then convert String
to SDO, this waste performance;
I illustrate the bug , using following code, schema and xml:
Schema: targetNamespace="http://test/sometype"
<xs:element name="st1E" type="ns:ST1"/>
<xs:complexType name="ST1">
<xs:sequence>
<xs:element name="a1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
XML: defined by the global element {http://test/sometype}st1E
<st1E xmlns="http://test/sometype"><a1>test</a1></st1E>
The Source code:
//the global element's xml
String xml="<st1E
xmlns=\"http://test/sometype\"><a1>test</a1></st1E>";
DataObject o = context.getXMLHelper().load(xml).getDataObject();
//loading string as SDO is correctly, so the assert is passed;
assertTrue(o.getType().getURI().equals(xsd_namespace));
//here I using DocumentBuilder to convert string to w3c Element;
Element e = DOMUtil.string2DOM(xml)
DataObject o = context.getXMLHelper().load(new DOMSource(e), null,
null).getDataObject();
//loaded SDO's type is AnyType, not the schema defined type; so the
assertion will failure;
Try{assertTrue(o.getType().getURI().equals(xsd_namespace));
}catch(){}
//finally I convert the Element back to string and reload it using
xml helper , the sdo is also correctly;
String s1 = DOMUtil.dom2String(e);//here I using a xsl transformer
to convert element back to string;
DataObject o = context.getXMLHelper().load(xml).getDataObject();
//re-loading string as SDO is also correctly, so the assert is
passed;
assertTrue(o.getType().getURI().equals(xsd_namespace));
java SDO XmlHelper cannot parse DOMSource to SDO correctly.
Posted by ext2 <xu...@tongtech.com>.
Hi:
In my application , I need convert the XML stored as
org.w3c.dom.element to SDO Object;
The XMLHelper support a method which can load the Source to SDO
Document.
But if I using this method to load DOMSource as SDO, it cannot work
correctly. The result SDO's type is AnyType, and is not correct schema
registered in SDO type context;
But if I convert the DOM to string first, then load the string as
SDO, the result is correct. Although it work, but this way will waste
performance.
Why ?
Does any know how to using TUSCANY SDO to convert DOMSource as sdo ?
Following is a sample xml
<xs:element name="st1E" type="ns:ST1"/>
<xs:complexType name="ST1">
<xs:sequence>
<xs:element name="a1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
The xml is :
<st1E xmlns="http://test/sometype">
<a1>test</a1>
</st1E>
SDO bugs? why cannot convert DOMSource to SDO?
Posted by ext2 <xu...@tongtech.com>.
Hi:
I have defined a type and a global element in my schema;
A file store a xml which format is same as the global element defined in
schema;
If I using SDO's XMLHelper loading the xml file as SDO, the result will be
successfully;
But if I loading the xml file to a w3c Element, and wrapping the Element
using a DOMSource; Then using XMLHelper loading the DOMSource as SDO, the
result will be failed. The SDO's type cannot not recognized by SDO. Only a
SDO:AnyType object is returned;
I am sure the loaded W3C Element is right, because if I save the
loaded XML Element back to a String, then convert the String to SDO, the
result will be right;
Why? Is SDO's bug?
Following is my schema and source code:
<xs:element name="st1E" type="ns:ST1"/>
<xs:complexType name="ST1">
<xs:sequence>
<xs:element name="a1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
The xml is :
<st1E xmlns="http://test/sometype">
<a1>test</a1>
</st1E>