[xsd-users] reading and writing non root elements

Greg Carter greg at permedia.ca
Wed Nov 22 18:33:14 EST 2006


Hello,

I wondering what the best approach would be for the following problem.  
I've defined a schema with one root element which is a complex type made 
up of many other complex types.  All the complex types are defined 
globally (no inner anonymous types).  Once the instance document is read 
in to a XSD generated class I wish to then operate on these sub types, 
changing the data, sending it off to other shared libs to do so.  These 
shared libraries can be written in another language.  So I thought the 
easiest thing to do would be to write the data out to an XML string to 
pass it to the other libraries.  Similarly, have the results passed back 
as an XML string that I can then read back into the XSD generated 
class.  It's assumed the developers of the other libraries will have 
access to schema binding tools similar to XSD.

XSD cxx-tree will generate serialization functions for the schema root 
elements.  Is there an easy way to do this for non root elements? 

I see that the class constructors can take a Xercesc DOMElement but I'm 
not sure how to get the string into this. 

Would I be better off defining separate schemas for any type that I need 
to use in this way (declaring a root element of that type)?

I can accomplish writing the data out to a string by using the 
--generate-ostream option.  If I were to read in the data generated by 
these stream functions to an XSD generated class, would I need to 
preface it with namespace (xmls=...) information so that the classes 
will parse it correctly?

Below is a simple schema that illustrates the problem.  After parsing 
the instance document that contains a MyType, I'll use the class 
instance of elOne, do something with it, then pass it off to a shared 
library, first converting it to XML.  There's no need to convert the 
whole document to XML, just the elOne.  Then I need to be able to parse 
the returned XML string back into an instance of ElOneType.

Thanks.


<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.blah.com/MySchema" version="1.0" 
xmlns="http://www.w3.org/2001/XMLSchema" 
xmlns:tns="http://www.blah.com/MySchema">
  <element name="rootEle" type="tns:MyType">
  </element>
  <complexType name="MyType">
    <sequence>
      <element name="elOne" type="tns:ElOneType">
      </element>
      <element name="elTwo" type="tns:ElTwoType">
      </element>
      <element name="elThree" type="tns:ElThreeType">
      </element>
    </sequence>
  </complexType>
...
</schema>



More information about the xsd-users mailing list