当前位置: 首页>>代码示例>>C++>>正文


C++ DOMDocument::createElement方法代码示例

本文整理汇总了C++中DOMDocument::createElement方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::createElement方法的具体用法?C++ DOMDocument::createElement怎么用?C++ DOMDocument::createElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOMDocument的用法示例。


在下文中一共展示了DOMDocument::createElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WriteEntity

void EntityXMLFileWriter::WriteEntity(World* world, EntityID entity)
{
    using namespace xercesc;
    DOMDocument* doc = m_DOMImplementation->createDocument(nullptr, X("Entity"), nullptr);
    DOMElement* root = doc->getDocumentElement();
    root->setAttribute(X("xmlns:xsi"), X("http://www.w3.org/2001/XMLSchema-instance"));
    root->setAttribute(X("xsi:noNamespaceSchemaLocation"), X("../Types/Entity.xsd"));
    root->setAttribute(X("xmlns:c"), X("components"));
    const std::string& name = world->GetName(entity);
    if (!name.empty()) {
        root->setAttribute(X("name"), X(name));
    }
    
    DOMElement* componentsElement = doc->createElement(X("Components"));
    root->appendChild(componentsElement);
    appentEntityComponents(componentsElement, world, entity);

    DOMElement* childrenElement = doc->createElement(X("Children"));
    root->appendChild(childrenElement);
    appendEntityChildren(childrenElement, world, entity);

    try {
        LocalFileFormatTarget* target = new LocalFileFormatTarget(X(m_FilePath.string()));
        DOMLSOutput* output = static_cast<DOMImplementationLS*>(m_DOMImplementation)->createLSOutput();
        output->setByteStream(target);
        m_DOMLSSerializer->write(doc, output);
        delete target;
    } catch (const std::runtime_error& e) {
        LOG_ERROR("Failed to save \"%s\": %s", m_FilePath.c_str(), e.what());
    }

    doc->release();
}
开发者ID:FakeShemp,项目名称:TacticalZ,代码行数:33,代码来源:EntityXMLFileWriter.cpp

示例2: appendEntityChildren

void EntityXMLFileWriter::appendEntityChildren(xercesc::DOMElement* parentElement, const World* world, EntityID entity)
{
    using namespace xercesc;
    DOMDocument* doc = parentElement->getOwnerDocument();

    auto childrenRange = world->GetEntityChildren().equal_range(entity);
    for (auto it = childrenRange.first; it != childrenRange.second; ++it) {
        EntityID childEntity = it->second;

        DOMElement* entityElement = doc->createElement(X("Entity"));
        const std::string& name = world->GetName(childEntity);
        if (!name.empty()) {
            entityElement->setAttribute(X("name"), X(name));
        }
        parentElement->appendChild(entityElement);

        DOMElement* componentsElement = doc->createElement(X("Components"));
        entityElement->appendChild(componentsElement);
        appentEntityComponents(componentsElement, world, childEntity);

        DOMElement* childrenElement = doc->createElement(X("Children"));
        entityElement->appendChild(childrenElement);
        appendEntityChildren(childrenElement, world, childEntity);
    }
}
开发者ID:FakeShemp,项目名称:TacticalZ,代码行数:25,代码来源:EntityXMLFileWriter.cpp

示例3: appendElementWithText

void appendElementWithText( DOMNode* cur, DOMNode* reply,
                            const char* name, const char* text,
                            int indentLevel, bool indent,
                            attrVect* attribute ) {

   MC2String indentStr( indentLevel*3, ' ' );
   indentStr.insert( 0, "\n" );   
   DOMDocument* doc = XMLTool::getOwner( reply );
   DOMElement* textElement = doc->createElement( X( name ) );
   if ( text != NULL ) {
      textElement->appendChild( doc->createTextNode( X( text ) ) );
   }

   if ( attribute != NULL ) {
      for ( uint32 i = 0 ; i < attribute->size() ; ++i ) {
         textElement->setAttribute( X( (*attribute)[ i ].first ), 
                                    X( (*attribute)[ i ].second ) );
      }
   }

   // Add textElement to cur
   if ( indent ) {
      cur->appendChild( doc->createTextNode( X( indentStr.c_str() ) ) );
   }
   cur->appendChild( textElement );
}
开发者ID:FlavioFalcao,项目名称:Wayfinder-Server,代码行数:26,代码来源:XMLServerElements.cpp

示例4: toXMLCommon

void EppResponseInfoFeeType::toXMLCommon( DOMDocument &doc, const DOMString &tag, DOMElement& inElement )
{
	EppCommandInfoFeeType::toXMLCommon(doc, tag, inElement);
	DOMElement* elm = NULL;

	if( NULL != this->fee )
	{
		for( unsigned int i = 0; i < fee->size(); i++ )
		{
			EppFeeFee* member = fee->elementAt(i);

			if( NULL != member )
			{
				elm = member->toXML(doc, "fee");

				if( NULL != elm )
				{
					inElement.appendChild(elm);
				}
			}
		}
	}

	if( this->fClass.length() > 0 )
	{
		elm = doc.createElement(XS("class"));
		elm->appendChild(doc.createTextNode(this->fClass));
		inElement.appendChild(elm);
	}
}
开发者ID:neustar,项目名称:registrar_toolkit,代码行数:30,代码来源:EppResponseInfoFeeType.cpp

示例5: addChild

	XmlNode addChild(const char *name) {
		XMLCh *tempStr = NULL;
		tempStr = XMLString::transcode(name);
		DOMElement *element = doc->createElement(tempStr);
		DOMNode *cnode = node->appendChild(element);
		XMLString::release(&tempStr);
		return XmlNode(cnode,doc);
	}
开发者ID:huilang22,项目名称:Projects,代码行数:8,代码来源:eft_cr_xml.cpp

示例6: handleFile

// 2006/12/16
void handleFile(char* filein, char* fileout, int mode)
{
  if (mode==_TXT2TXTMODE) {
    int result;
    if (filein == NULL) {
      if (fileout == NULL) result = seg->segmentStream(cin,cout);
      else {
        ofstream* fout = new ofstream(fileout);
        result = seg->segmentStream(cin,*fout);
        fout->close();
      }
    } else {
      ifstream* fin = new ifstream(filein);
      ofstream* fout = new ofstream(fileout);
      result = seg->segmentStream(*fin,*fout);
      fin->close();
      fout->close();
    } 
    // BROKEN, result is false 2006/11/07
    //if (verbose) 
    //  cerr << "> Segmented in " << result << " sentences." << endl;
  } 
  else if (mode==_TXT2XMLMODE) {

    DOMDocument* out = xmlInterface->createDocument("document");
    DOMElement* root = out->getDocumentElement();
    if (filein != NULL)
      root->setAttribute(XMLString::transcode("filename"),
                         XMLString::transcode(filein));
    DOMElement* contents = out->createElement(XMLString::transcode("content"));
    DOMElement* body = out->createElement(XMLString::transcode("body"));
    DOMElement* section = out->createElement(XMLString::transcode("section"));
    section->setAttribute(XMLString::transcode("analyze"),
                          XMLString::transcode("yes"));
    DOMText* text = 
      out->createTextNode(XMLString::transcode(getFileContents(filein).c_str()));
    section->appendChild(text);
    body->appendChild(section);
    contents->appendChild(body);
    root->appendChild(contents);
    handleDocument(out,fileout);
  } 
  else if  (mode==_XML2XMLMODE) {
    handleDocument(xmlInterface->parse(filein),fileout);
  }
}
开发者ID:lgwizme,项目名称:macaon,代码行数:47,代码来源:main.cpp

示例7: toXMLCommon

void EppCommandCheckFeeType::toXMLCommon( DOMDocument &doc, const DOMString &tag, DOMElement& inElement )
{
	DOMElement* elm = NULL;

	if( this->name.length() > 0 )
	{
		elm = doc.createElement(XS("name"));
		elm->appendChild(doc.createTextNode(this->name));
		inElement.appendChild(elm);
	}
	EppCommandInfoFeeType::toXMLCommon(doc, tag, inElement);
}
开发者ID:neustar,项目名称:registrar_toolkit,代码行数:12,代码来源:EppCommandCheckFeeType.cpp

示例8:

//
// set_element_value
//
void Utils::
set_element_value (xercesc::DOMElement * e,
                   const GAME::Xml::String & element,
                   const GAME::Xml::String & value)
{
  using xercesc::DOMNode;
  using xercesc::DOMNodeList;
  using xercesc::DOMDocument;

  // There should be only 1 <name> tag in the list.
  GAME::Xml::String nodename;
  DOMNode * node = 0;
  DOMNodeList * list = e->getChildNodes ();
  size_t len = list->getLength ();

  for (size_t i = 0; i < len; ++ i)
  {
    // Get the name of the next node.
    node = list->item (i);
    nodename.set (node->getNodeName (), false);

    if (nodename == element)
      break;

    // Reset the node.
    node = 0;
  }

  if (node == 0)
  {
    // We need to create the <name> element.
    DOMDocument * doc = e->getOwnerDocument ();
    node = doc->createElement (element);
    e->appendChild (node);
  }

  // Since there are no child nodes, we can just set the
  // text content to the name of the object.
  node->setTextContent (value);
}
开发者ID:SEDS,项目名称:GAME,代码行数:43,代码来源:XME_Utils.cpp

示例9: XS

PerfPart::PerfPart( PMLDocument *doc, ScorePart *part ){
    m_doc = doc;

    DOMDocument *domdoc = part->getElement()->getOwnerDocument();
    m_scorePart = part;
    m_element = domdoc->createElement( XS("perfpart") );       //'perfpart' tag is the m_element for this class

  //create part attribute
    m_element->setAttribute( XS("part"), XS( m_scorePart->getID().c_str() ) );
  
  //append part to performance element
    DOMElement *perf = (DOMElement*)domdoc->getElementsByTagName(XS("performance"))->item(0);
    perf->appendChild( m_element );

    DOMNodeList *nl = m_element->getElementsByTagName(XS(PNote::Tag));

    for( int i=0; i<nl->getLength(); i++ ){
        m_notes.push_back( new PNote( m_doc, (DOMElement*)nl->item(i) ) );

    }

}
开发者ID:jmacritchie,项目名称:DougMatcher,代码行数:22,代码来源:perfpart.cpp

示例10: align

void SNote::align( PNote *note, bool correct ){

    DOMNodeList *list = m_element->getElementsByTagName(XS("align"));
    DOMElement *align;

    if( list->getLength() == 0 ){
        DOMDocument *doc = m_element->getOwnerDocument();
        align = doc->createElement(XS("align"));
        m_element->appendChild(align);
    }
    else{
        align = (DOMElement*)list->item(0);
    }


    align->setAttribute( XS("note"), XS(note->getID().c_str()) );
		       
    if( correct )
        setText( align, "correct" );
    else
        setText( align, "wrong" );
}
开发者ID:jmacritchie,项目名称:DougMatcher,代码行数:22,代码来源:snote.cpp

示例11: saveConfig

bool ClsDataClientConfigWriter::saveConfig(string strFileName, list<ClsDataClientConfig> lstConfigs) {
//    cout << "ClsDataClientConfigWriter::saveConfig(string strFileName, list<ClsDataClientConfig> lstConfigs)" << endl;

    if(!bXMLPlatformInitialized){
	try {
	    XMLPlatformUtils::Initialize();
	}
	catch(const XMLException& toCatch) {
	    cerr << "Error during Xerces-c Initialization.\n"
		 << "  Exception message:"
		 << toCatch.getMessage() << endl;
	    bXMLPlatformInitialized = false;
	    return false;
	}
	bXMLPlatformInitialized = true;
    }


    DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode((const char*)"Range"));

    DOMDocumentType *dtd = impl->createDocumentType(XMLString::transcode(ConfigTagLibrary::DataManagerConfiguration()),
						    XMLString::transcode("-//INI/iqr421"),
						    XMLString::transcode("iqrDataManagerConfiguration.dtd"));

    DOMDocument *ddocConfig = impl->createDocument(0, XMLString::transcode(ConfigTagLibrary::DataManagerConfiguration()), dtd);

    DOMElement *delemConfig;
    delemConfig = ddocConfig->getDocumentElement();

    list<ClsDataClientConfig>::iterator itConfigs;
    for(itConfigs=lstConfigs.begin(); itConfigs != lstConfigs.end(); itConfigs++){
	string strID = (*itConfigs).getID();
	string strType =  (*itConfigs).getType();
	pair<int,int> pPosition =  (*itConfigs).getPosition();
	pair<int,int> pGeometry =  (*itConfigs).getGeometry();

 	DOMElement *delemDataClient;
	delemDataClient = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::DataClientTag()));
	delemDataClient->setAttribute(XMLString::transcode(ConfigTagLibrary::TypeTag()), XMLString::transcode(strType.c_str()));
	delemDataClient->setAttribute(XMLString::transcode(ConfigTagLibrary::IDTag()), XMLString::transcode(strID.c_str()));
	delemConfig->appendChild(delemDataClient);

 	DOMElement *delemPosition;
	delemPosition = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::PositionTag()));
	delemPosition->setAttribute(XMLString::transcode(ConfigTagLibrary::PositionXTag()), 
				    XMLString::transcode(iqrUtils::int2string(pPosition.first).c_str()));
	delemPosition->setAttribute(XMLString::transcode(ConfigTagLibrary::PositionYTag()),
				    XMLString::transcode(iqrUtils::int2string(pPosition.second).c_str()));
	delemDataClient->appendChild(delemPosition);

 	DOMElement *delemGeometry;
	delemGeometry = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::Geometry()));
	delemGeometry->setAttribute(XMLString::transcode(ConfigTagLibrary::GeometryWidthTag()), 
				    XMLString::transcode(iqrUtils::int2string(pGeometry.first).c_str()));
	delemGeometry->setAttribute(XMLString::transcode(ConfigTagLibrary::GeometryHeightTag()), 
				    XMLString::transcode(iqrUtils::int2string(pGeometry.second).c_str()));
	delemDataClient->appendChild(delemGeometry);



	list<pair<string, string> > lstParameters = (*itConfigs).getListParameters();
	list<pair<string, string> >::iterator itLstParameters;
	for(itLstParameters = lstParameters.begin(); itLstParameters != lstParameters.end(); itLstParameters++){
	    string strParamName = (*itLstParameters).first;
	    string strParamValue = (*itLstParameters).second;
	    DOMElement *delemParameter;
	    delemParameter = ddocConfig->createElement(XMLString::transcode(strParamName.c_str()));
	    delemDataClient->appendChild(delemParameter);
	    DOMText *dtxtParamValue = ddocConfig->createTextNode(XMLString::transcode(strParamValue.c_str()));
	    delemParameter->appendChild(dtxtParamValue);
	}

 	DOMElement *delemSVD;
	delemSVD = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::StateVariableDisplayTag()));
	delemDataClient->appendChild(delemSVD);

	list<ClsStateVariableDisplayConfig>lstSVDConfigs =  (*itConfigs).getListStateVariableDisplayConfig();
	list<ClsStateVariableDisplayConfig>::iterator itSVD;
	for(itSVD = lstSVDConfigs.begin(); itSVD != lstSVDConfigs.end(); itSVD++){
	    DOMElement *delemStateVariable;
	    delemStateVariable = ddocConfig->createElement(XMLString::transcode(ConfigTagLibrary::StateVariableDisplaysTag()));
	    delemSVD->appendChild(delemStateVariable);
	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::IDTag()), 
					     XMLString::transcode((*itSVD).getID().c_str()));
	    
/*
	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::TypeTag()), 
					     XMLString::transcode((*itSVD).getItemType().c_str()));
*/
	
	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::ItemIDTag()), 
					     XMLString::transcode((*itSVD).getItemID().c_str()));

	    delemStateVariable->setAttribute(XMLString::transcode(ConfigTagLibrary::SelectedIndicesTag()), 
					     XMLString::transcode((*itSVD).getSelectedIndices().c_str()));

	    list<pair<string, string> > lstParametersSVD = (*itSVD).getListParameters();
	    list<pair<string, string> >::iterator itLstParametersSVD;
	    for(itLstParametersSVD = lstParametersSVD.begin(); itLstParametersSVD != lstParametersSVD.end(); itLstParametersSVD++){
		string strParamName = (*itLstParametersSVD).first;
//.........这里部分代码省略.........
开发者ID:jeez,项目名称:iqr,代码行数:101,代码来源:ClsDataClientConfigWriter.cpp

示例12: main

int  main()
{
	try {
		XMLPlatformUtils::Initialize();
	}
	catch (const XMLException& toCatch) {
        char *pMessage = XMLString::transcode(toCatch.getMessage());
        fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n"
                        "  Message is: %s\n", pMessage);
        XMLString::release(&pMessage);
        return -1;
    }

    /*
    Range tests include testing of

    createRange

    setStart, setStartBefore. setStartAfter,
    setEnd, setEndBefore. setEndAfter
    getStartContainer, getStartOffset
    getEndContainer, getEndOffset
    getCommonAncestorContainer
    selectNode
    selectNodeContents
    insertNode
    deleteContents
    collapse
    getCollapsed
    surroundContents
    compareBoundaryPoints
    cloneRange
    cloneContents
    extractContents
    toString
    detach
    removeChild
    */
    {

        XMLCh tempStr[100];
        XMLString::transcode("Range",tempStr,99);
        {
            DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
            DOMDocument* doc = impl->createDocument();

            //Creating a root element
            DOMElement*     root = doc->createElement(xBody);
            doc->appendChild(root);

            //Creating the siblings of root
            DOMElement*     E11 = doc->createElement(xH1);
            root->appendChild(E11);

            DOMElement*     E12 = doc->createElement(xP);
            root->appendChild(E12);

            //Attaching texts to siblings
            DOMText*        textNode1 = doc->createTextNode(xTitle);
            E11->appendChild(textNode1);

            DOMText*        textNode11 = doc->createTextNode(xAnotherText);
            E11->appendChild(textNode11);

            DOMText*        textNode2 = doc->createTextNode(xBlahxyz);
            E12->appendChild(textNode2);

            DOMText*     E210 = doc->createTextNode(xInsertedText);

            doc->release();


        }


        {
            //DOM Tree and some usable node creation
            DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
            DOMDocument* doc = impl->createDocument();

            //Creating a root element
            DOMElement*     root = doc->createElement(xBody);
            doc->appendChild(root);

            //Creating the siblings of root
            DOMElement*     E11 = doc->createElement(xH1);
            root->appendChild(E11);

            DOMElement*     E12 = doc->createElement(xP);
            root->appendChild(E12);

            //Attaching texts to siblings
            DOMText*        textNode1 = doc->createTextNode(xTitle);
            E11->appendChild(textNode1);

            DOMText*        textNode11 = doc->createTextNode(xAnotherText);
            E11->appendChild(textNode11);

            DOMText*        textNode2 = doc->createTextNode(xBlahxyz);
            E12->appendChild(textNode2);
//.........这里部分代码省略.........
开发者ID:andyburke,项目名称:bitflood,代码行数:101,代码来源:RangeTest.cpp

示例13: main

int  main()
{
	try {
		XMLPlatformUtils::Initialize();
	}
	catch (const XMLException& toCatch) {
        char *pMessage = XMLString::transcode(toCatch.getMessage());
        fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n"
                        "  Message is: %s\n", pMessage);
        XMLString::release(&pMessage);
        return -1;
    }

    // Create a XMLCh buffer for string manipulation
    XMLCh tempStr[4000];
    XMLCh featureStr[100];
    XMLString::transcode("Traversal",featureStr,99);



    //
    //  Doc - Create a small document tree
    //

    {
        //creating a DOM Tree
         /* Tests are based on the tree structure below
           doc - root - E11 (attr01) - textNode1
                                     - E111
                                     - E112
                                     - cdataSec
                      - E12 (attr02) - textNode2
                                     - E121
                                     - E122
                      - E13          - E131
                                     - docPI
                      - comment
         */

        DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(featureStr);
        DOMDocument* doc = impl->createDocument();

        //Creating a root element
        XMLString::transcode("RootElement", tempStr, 3999);
        DOMElement*     root = doc->createElement(tempStr);
        doc->appendChild(root);

        //Creating the siblings of root
        XMLString::transcode("FirstSibling", tempStr, 3999);
        DOMElement*     E11 = doc->createElement(tempStr);
        root->appendChild(E11);

        XMLString::transcode("SecondSibling", tempStr, 3999);
        DOMElement*     E12 = doc->createElement(tempStr);
        root->appendChild(E12);

        XMLString::transcode("ThirdSibling", tempStr, 3999);
        DOMElement*     E13 = doc->createElement(tempStr);
        root->appendChild(E13);

        //Attaching texts to few siblings
        XMLString::transcode("Text1", tempStr, 3999);
        DOMText*        textNode1 = doc->createTextNode(tempStr);
        E11->appendChild(textNode1);

        XMLString::transcode("Text2", tempStr, 3999);
        DOMText*        textNode2 = doc->createTextNode(tempStr);
        E12->appendChild(textNode2);

        //creating child of siblings
        XMLString::transcode("FirstSiblingChild1", tempStr, 3999);
        DOMElement*     E111 = doc->createElement(tempStr);
        E11->appendChild(E111);

        XMLString::transcode("Attr01", tempStr, 3999);
        DOMAttr*        attr01  = doc->createAttribute(tempStr);
        DOMNode* rem = E11->setAttributeNode(attr01);
        if (rem)
            rem->release();

        XMLString::transcode("FirstSiblingChild2", tempStr, 3999);
        DOMElement*     E112 = doc->createElement(tempStr);
        E11->appendChild(E112);

        XMLString::transcode("SecondSiblingChild1", tempStr, 3999);
        DOMElement*     E121 = doc->createElement(tempStr);
        E12->appendChild(E121);

        XMLString::transcode("Attr01", tempStr, 3999);
        DOMAttr* attr02 = doc->createAttribute(tempStr);
        rem = E12->setAttributeNode(attr02);
        if (rem)
            rem->release();

        XMLString::transcode("SecondSiblingChild2", tempStr, 3999);
        DOMElement*     E122 = doc->createElement(tempStr);
        E12->appendChild(E122);

        XMLString::transcode("ThirdSiblingChild1", tempStr, 3999);
        DOMElement*     E131 = doc->createElement(tempStr);
//.........这里部分代码省略.........
开发者ID:kanbang,项目名称:Colt,代码行数:101,代码来源:Traversal.cpp

示例14: buildParameterSetXML

/**
 * This method converts the entries in the map (created from the command-line arguments)
 * into XML which will then be fed as input into the parameter handling code (i.e. ParameterSet class).
 */
string parameterTask::buildParameterSetXML(const string & xmlFileNamePrefix) 
{
	string retVal;
	try {
		XMLPlatformUtils::Initialize();
	}
	catch (const XMLException& toCatch)
	{
		ACS_LOG(LM_ERROR, "parameterTask::buildParameterSetXML", 
			(LM_ERROR, "Error - XMLException - info: %s\n", StrX(toCatch.getMessage()).localForm()))
	}
	DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(StrX("XML 2.0").unicodeForm());

	if (impl != NULL)
	{
		try
		{
			// create a new DOMDocument which we will populate with 
			// entries from the command-line parameters, in order to 
			// make an xml version of the parameter set for use internally
			string qualifiedName(PARAMETERSET_NAMESPACE_PREFIX);
			qualifiedName.append(":").append(PARAMETERSET_STRING);

			DOMDocument* doc = impl->createDocument(
				StrX(PSET_NAMESPACE_URI).unicodeForm(), // root element namespace URI.
				StrX(qualifiedName.c_str()).unicodeForm(), // root element name
				0); // document type object (DTD).

			doc->setStandalone(true);

			// set our internal auto_ptr to point to the new document
			this->domDocument.reset(doc);

			string schemaHint(PSET_NAMESPACE_URI);
			schemaHint.append(" ").append(PARAMETERSET_SCHEMA_NAME);
			DOMElement* rootElem = doc->getDocumentElement();
			rootElem->setAttribute(StrX("xmlns:xsi").unicodeForm(), StrX("http://www.w3.org/2001/XMLSchema-instance").unicodeForm());
			rootElem->setAttribute(StrX("xsi:schemaLocation").unicodeForm(), 
				StrX(schemaHint.c_str()).unicodeForm());

			DOMElement*  psetdefElem = doc->createElement(StrX(PSETDEF_STRING).unicodeForm());
			rootElem->appendChild(psetdefElem);

			string xmlFileName = xmlFileNamePrefix + ".xml";
			DOMText* psetdefValTextNode = doc->createTextNode(StrX(xmlFileName.c_str()).unicodeForm());
			psetdefElem->appendChild(psetdefValTextNode);
			DOMElement*  nameElem = doc->createElement(StrX(NAME_STRING).unicodeForm());
			rootElem->appendChild(nameElem);
			DOMText* nameValTextNode = doc->createTextNode(StrX("command-line values").unicodeForm());
			nameElem->appendChild(nameValTextNode);

			map<string, vector<string> >::iterator position;
			// for each parameter in the parameterMap
			for(position = parameterMap.begin(); position != parameterMap.end(); ++position) {
				// determine the type by looking it up in our parameter set definition, i.e. psetdef 
				// (which we have obtained by parsing the task's psetdef xml file containing the task's metadata)
				// and add an element of the proper type to the XML document being constructed, with name equal to the
				// key portion of the current map entry, value equal to the value portion of the current map entry.
				ParamSetDef::paramTypesEnum paramType = paramSetDef->getParamTypeForName(position->first);
				switch(paramType) {
					case ParamSetDef::BOOL: {
						DOMElement *boolElem = createBoolElement(position->first, position->second, doc);
						rootElem->appendChild(boolElem);
						break;
					}
					case ParamSetDef::INT: {
						DOMElement *intElem = createIntElement(position->first, position->second, doc);
						rootElem->appendChild(intElem);
						break;
					}
					case ParamSetDef::INT_ARRAY: {
						DOMElement *intArrayElem = createIntArrayElement(position->first, position->second, doc);
						rootElem->appendChild(intArrayElem);
						break;
					}
					case ParamSetDef::DOUBLE: {
						DOMElement *doubleElem = createDoubleElement(position->first, position->second, doc);
						rootElem->appendChild(doubleElem);
						break;
					}
					case ParamSetDef::DOUBLE_ARRAY: {
						DOMElement * doubleArrayElem = 
							createDoubleArrayElement(position->first, position->second, doc);
						rootElem->appendChild(doubleArrayElem);
						break;
					}
					case ParamSetDef::STRING: {
						DOMElement *stringElem = createStringElement(position->first, position->second, doc);
						rootElem->appendChild(stringElem);
						break;
					}
					case ParamSetDef::STRING_ARRAY: {
						DOMElement * stringArrayElem = createStringArrayElement(position->first, position->second, doc);
						rootElem->appendChild(stringArrayElem);
						break;
					}
//.........这里部分代码省略.........
开发者ID:ACS-Community,项目名称:ACS,代码行数:101,代码来源:parameterTask.cpp

示例15:

/*=========================================================================+
	Build_Return_XML:
		Build the XML block that eTrust Admin expects the program exit
		to return.

		<eTExitReturn>
			<eTExitReturnCategory></eTExitReturnCategory>
			<eTExitReturnNative></eTExitReturnNative>
			<eTExitContinue></eTExitContinue>
			<eTExitLogMsg></eTExitLogMsg>
			<eTExitCustom></eTExitCustom>
		</eTExitReturn>

	    The return XML buffer provided by eTrust Admin is over 4000 bytes
		long.  There will be no problem fitting the entire output XML
		document into this buffer unless sLogMessage or the custom_msg built
		from the return values array is very long.  Thus, this code attempts
		first to build an XML buffer with all of the provided information
		and if it is too long does the following:
			case 1:  custom_msg is provided
				--> generate a failure exit return block with no custom_msg

			case 2:  sLogMessage is provided, but no custom_msg
				--> replace the very long sLogMessage with a short one.

+=========================================================================*/
void
ExitXMLBlock::Build_Return_XML(
		STATUS_T	tStatus,
		bool		bContinueEtaExecution,
		string		sLogMessage,
		string &	sReturnXML,						// OUT
		int			iMaxReturnLength,
		bool		bObscureValue  // = false
	)
{
	int iRc;
	string	suValue;
	UTF8	pszuValue[32];
	XMLCh*	pxcValue;

	pxcValue = UTF8toUTF16(UTFEXIT_EXITRETURN);
	DOMDocument* pDocument = ExitXMLBlock::g_pImplementation->createDocument(0, pxcValue, 0);
	delete pxcValue;
	DOMElement* pRootElement = pDocument->getDocumentElement();

	// ...eTrust Admin Category.
	suValue = Convert_Status_To_Category_String(tStatus);
	iRc = Add_Element(pDocument, pRootElement, UTFEXIT_EXITRETURNCATEGORY, suValue);

	// ...Program exit return code.
	sprintf(pszuValue, "%d", tStatus);
	iRc = Add_Element(pDocument, pRootElement, UTFEXIT_EXITRETURNNATIVE, pszuValue);

	// ...Should eTrust Admin continue execution?
	suValue = (bContinueEtaExecution ? UTFEXIT_TRUE : UTFEXIT_FALSE);
	iRc = Add_Element(pDocument, pRootElement, UTFEXIT_EXITCONTINUE, suValue);

	// ...Log message.
	if (!sLogMessage.empty()) {
		iRc = Add_Element(pDocument, pRootElement, UTFEXIT_EXITLOGMSG, sLogMessage);
	}

	// ...Custom message (used for return values today; and perhaps for
	// other exit-type specific purposes in the future).
	if (m_vsReturnValues.size() > 0) {
		pxcValue = UTF8toUTF16(UTFEXIT_EXITCUSTOM);
        DOMElement* pElement = pDocument->createElement(pxcValue);
		delete pxcValue;
        pRootElement->appendChild(pElement);

		// Add each return value as <eTFuncReturn>...</eTFuncReturn>
		for (unsigned int iIndex = 0; iIndex <  m_vsReturnValues.size(); iIndex++) {
			if (bObscureValue) {	// add the obscured attribute for passwords
				Add_Element(
					pDocument,
					pElement,
					UTFEXIT_CF_FUNCRETURN,
					m_vsReturnValues[iIndex],
					"obscured",
					"yes");
			} else {
				Add_Element(
					pDocument,
					pElement,
					UTFEXIT_CF_FUNCRETURN,
					m_vsReturnValues[iIndex]);
			}
		}
	}

	// Generate the return XML string
	DOMBuilder* pBuilder;	// Parser
	DOMWriter*	pWriter;	// Serializer

	pWriter = ExitXMLBlock::g_pImplementation->createDOMWriter();
	pBuilder = ExitXMLBlock::g_pImplementation->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
	pWriter->setFeature(XMLUni::fgDOMXMLDeclaration, false);
	pBuilder->resetDocumentPool();

//.........这里部分代码省略.........
开发者ID:crespo2014,项目名称:cpp-lib,代码行数:101,代码来源:ExitXMLBlock.cpp


注:本文中的DOMDocument::createElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。