[xsd-users] How to add data to xml any type of object

Babinskas, Albert albert.babinskas at imagingsciences.com
Wed Sep 11 10:30:05 EDT 2013


Hi Boris,
I got it to work, but the solution doesn't not look elegant. I will provide my XSD and code to show you what I mean.
Here is my XSD:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://VixWinXml" xmlns:tns="http://VixWinXml" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="annotationFile" type="tns:file_t"/>	
<xs:complexType name="file_t">
	<xs:sequence>
		<xs:element name="content" type="xs:base64Binary"/>
		<xs:element name="contentType" type="xs:string" minOccurs="0"/>		 
		<xs:element name="path" type="xs:string" minOccurs="0"/>
	</xs:sequence>	
</xs:complexType>
</xs:schema>

And Another XSD snippet:
<xs:complexType name="appSpecificXml_t">
    <xs:complexContent>
      <xs:extension base="tns:appSpecificData_t">
        <xs:sequence>
          <xs:element name="dexis" type="tns:brandXml_t" minOccurs="0"/>
          <xs:element name="gendex" type="tns:brandXml_t" minOccurs="0"/>
          <xs:element name="soredex" type="tns:brandXml_t" minOccurs="0"/>
          <xs:element name="instrumentarium" type="tns:brandXml_t" minOccurs="0"/>
          <xs:element name="kavo" type="tns:brandXml_t" minOccurs="0"/>
          <xs:element name="other" type="tns:brandXml_t" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="brandXml_t">
    <xs:sequence>
      <xs:any processContents="skip" namespace="##other" />
    </xs:sequence>
  </xs:complexType>

And Here is my code snippet:
VixWinXml::file_t annotationFile(xml_schema::base64_binary(fileContent, size));
stringstream sstream;		
VixWinXml::annotationFile(sstream, annotationFile, localSerializationMap);
xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument> domPtr = ObjectParser::parseToDom(sstream, "id", false);
add_namespace(domPtr.get(), domPtr->getDocumentElement(), "http://VixWinXml");
xercesc::DOMElement& e = *domPtr->getDocumentElement();
schema1::datawarehouse::brandXml_t b(e, xml_schema::flags::dont_validate, 0);
b.any().release();
b.any(e);	

I don't get default constructor created for me by Codesynthesis XSD. I have these 3 constructors that are created: 
// Constructors.
brandXml_t (const ::xercesc::DOMElement&);
brandXml_t (const ::xercesc::DOMElement& e,
		  ::xml_schema::flags f = 0,
		  ::xml_schema::container* c = 0);
brandXml_t (const brandXml_t& x,
		  ::xml_schema::flags f = 0,
		  ::xml_schema::container* c = 0);
				  
Ideally I would like to add my object (annotationFile) to add to brandXml_t any.
If I would have default empty constructor, I could add any object without "adding namespaces". I could write constructor myself, but I would like Codesynthesis to generate it.


-Albert

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Wednesday, September 11, 2013 5:58 AM
To: Babinskas, Albert
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] How to add data to xml any type of object

Hi Albert,

Babinskas, Albert <albert.babinskas at imagingsciences.com> writes:

> I still have the remaining question of how can I add object to this 
> xs:any type? 'Wildcard' example shows that you create 'envelope'
> object and then get its DOMDocument. I cannot instantiate my object 
> since it requires to pass it DOMElement.

You don't need to pass DOMDocument when creating your object (this constructor is used internally by XSD for XML parsing). Instead, your object will have a number of other constructors and one of them will take an argument for every required attribute and element (if you don't have any, then it will become the default constructor). That's also how the 'wildcard' example creates a new 'binary' object (driver.cxx:124) and adds it to the envelope.

If you are still having trouble instantiating your object, please show us the relevant XML Schema definitions.

Boris


Please be advised that this email may contain confidential 
information.  If you are not the intended recipient, please notify us 
by email by replying to the sender and delete this message.  The 
sender disclaims that the content of this email constitutes an offer 
to enter into, or the acceptance of, any agreement; provided that the 
foregoing does not invalidate the binding effect of any digital or 
other electronic reproduction of a manual signature that is included 
in any attachment.





More information about the xsd-users mailing list