[xsd-users] How to apend an anytype child element into the object model

liyubo liyubo at dayang.com.cn
Tue Nov 26 05:16:42 EST 2013


Hi, Boris, i have a problem to add a anytype element into the parent model.

Here is my schema

<?xml version="1.0" encoding="UTF-8"?>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="Data" type="DataContents">
              <xs:annotation>
                   <xs:documentation>Comment describing your root element</xs:documentation>
              </xs:annotation>
         </xs:element>
 
         <xs:complexType name="DataContents">
              <xs:annotation>
                   <xs:documentation>Comment describing your root element</xs:documentation>
              </xs:annotation>
              <xs:sequence>
                   <xs:element name="DataItem" type="xs:anyType" minOccurs="0"/>
              </xs:sequence>
        </xs:complexType>
 
</xs:schema>


The  [DataItem]  is anyType, and I want append a CDATATEXT section,the code is


int
main (int argc, char* argv[])
{
  using namespace xercesc;

  XMLPlatformUtils::Initialize ();

  ::DataContents  dataContents;

  DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"LS");

  DOMDocument* doc = impl->createDocument(0, L"DataItem", 0);
  DOMElement* eRoot = doc->getDocumentElement();

  DOMElement* eText = doc->createElement(L"text");
  DOMCDATASection* data = doc->createCDATASection(L"1234567 This is a CDATA!");
  eText->appendChild(data);

  eRoot->appendChild(eText);

  ::DataContents::DataItem_type item(*eRoot);

  dataContents.DataItem(item);

  Data(std::cout, dataContents);

  XMLPlatformUtils::Terminate ();

  return 0;
}


I just use the DOMElement i manually created to init  the anytype .The xml_schema::type constructor shows it coulde be created by a DOMElement. But it seems does not work.   I don't know how to create the anytype object model, it is only can created by a DOMElement? 

I also try to use like this
xml_schema::type& t (*reinterpret_cast<xml_schema::type*> (ae->getUserData (xml_schema::dom::tree_node_key)));
in [2.5.2 Mapping for anyType] but it will get a crash,because t get a null.

Please help!

2013-11-26



liyubo


More information about the xsd-users mailing list