Hi,

I'm trying to convert an object to an OMElement, as described in the "ADB Howto" (http://ws.apache.org/axis2/1_0/adb/adb-howto.html).

In fact, I'm doing exactly the same as in the code snippets in the howto -- using the same xml and code examples. I'm hitting a problem when I have created the OMElement using the StAXOMBuilder: the OMElement that is produced is *not* the top-level "myElement" element, but one of the sub-elements "varString".

I had to change both the XSD and the XML a bit in order to get the example correct and working:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://soapinterop.org/types"
        targetNamespace="http://soapinterop.org/types"
        elementFormDefault="qualified">
 <complexType name="SOAPStruct">
  <sequence>
   <element name="varString" type="xsd:string"/>
   <element name="varInt" type="xsd:int"/>
   <element name="varFloat" type="xsd:float"/>
  </sequence>
  <attribute name="foo"/>
 </complexType>
 <element name="myElement" type="tns:SOAPStruct"/>
</schema>

<myElement
         xmlns="http://soapinterop.org/types"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://soapinterop.org/types test.xsd"
        foo="bar">
  <varString>Hello</varString>
  <varInt>5</varInt>
  <varFloat>3.3</varFloat>
</myElement>

I have added a foo attribute to the toplevel element to further illustrate the problem.

I have pushed the xsd through XSD2Java, resulting in MyElement.java and SOAPStruct.java.
The first problem is that the foo attribute is not modeled anywhere in these two classes.

The following code reads the xml file, parses it to a MyElement instance, and then creates an OMElement of it, just as in the howto:

        XMLStreamReader reader = XMLInputFactory.newInstance().
                createXMLStreamReader(new FileReader("test.xml"));
        MyElement elt = MyElement.Factory.parse(reader);
        XMLStreamReader r = elt.getPullParser(null);
        OMElement omElt =  new StAXOMBuilder(r).getDocumentElement();
        System.out.println(omElt);

The output reads
        <varString xmlns="http://soapinterop.org/types">Hello</varString>

What I expect to see (and actually need) is the full xml - not just the first sub element.

Is the shown behaviour normal? If so, what do I need to do to get an OMElement that represents the full xml document?

Thanks,
Tom


Reply via email to