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


C++ DOMElement::removeChild方法代码示例

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


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

示例1: main

int main( int argc, char **argv ){

 
  m_doc = openDocument( argv[1] );

  DOMElement *root = m_doc->getDocumentElement();
  DOMNodeList *parts = root->getElementsByTagName(XS("part"));


  /*

  */
  DOMElement *part1 = (DOMElement*)parts->item(0);
  DOMElement *part2 = (DOMElement*)parts->item(1);

  mergeParts( part1, part2 );


  root->removeChild( part2 );
  DOMElement *partlist = getSingleElement( root, "part-list" );
  partlist->removeChild( partlist->getElementsByTagName(XS("score-part"))->item(1) );


  writeFile("merged.xml");



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

示例2: serializeEachMoFileInDirectory

int ModelicaXML::serializeEachMoFileInDirectory(char *directoryName)
{
  typedef std::string mstring;
  mstring filename;
  l_list dirList;
  getDirectoryStructure(directoryName, dirList);
  std::list<char*>::const_iterator it;
  for(it=dirList.begin(); it!=dirList.end(); ++it)
  {
    l_list fileList;
    getFileList(*it, fileList, "*.mo");
    if (fileList.size()) fileList = sortMoFiles(fileList);
    cout << "Found: " << fileList.size() << " *.mo files in directory: " << *it  << endl;
    if (!fileList.size()) { continue; }
    std::list<char*>::const_iterator itFileList;
    for(itFileList=fileList.begin(); itFileList!=fileList.end(); ++itFileList)
    {
      filename = mstring(*itFileList);
      cout << " [" << filename << "]" << endl;
      DOMElement* pModelicaXML = createModelicaXMLDOMElement(filename.c_str());
      // if is not NULL append it to the <modelica></modelica> element
      if (pModelicaXML) pRootElementModelica->appendChild(pModelicaXML);
      // vomit the current XML Document to file
      std::string xmlFile(filename.c_str());
      xmlFile += ".xml";
      serializeXMLDocumentToFile(xmlFile);
      if (pModelicaXML) pRootElementModelica->removeChild(pModelicaXML);
    }
    if (fileList.size()) cout << endl;
  }
  return 0;
}
开发者ID:AntonDV235,项目名称:OMCompiler,代码行数:32,代码来源:ModelicaXML.cpp

示例3: 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

示例4: main

int main( )
{
    try {
        // Initialize Xerces and retrieve a DOMImplementation.
        XercesInitializer   init;
        DOMImplementation*  impl = 
            DOMImplementationRegistry::getDOMImplementation(
                fromNative("LS").c_str( )
            );
        if (impl == 0) {
            cout << "couldn't create DOM implementation\n";
            return EXIT_FAILURE;
        }

        // Construct a DOMBuilder to parse animals.xml.
        DOMPtr<DOMBuilder>  parser = 
            static_cast<DOMImplementationLS*>(impl)->
                createDOMBuilder(
                    DOMImplementationLS::MODE_SYNCHRONOUS, 0
                );
        CircusErrorHandler  err;
        parser->setErrorHandler(&err);

        // Parse animals.xml.
        DOMDocument*  doc = 
            parser->parseURI("animals.xml");
        DOMElement*   animalList = doc->getDocumentElement( );

        // Create XPath expression.
        auto_ptr<XPathEvaluator>   
            evaluator(XPathEvaluator::createEvaluator( ));
        auto_ptr<XPathNSResolver>  
            resolver(evaluator->createNSResolver(animalList));
        auto_ptr<XPathExpression>  
            xpath(
                evaluator->createExpression(
                    fromNative(
                        "animalList/animal[child::name='Herby']"
                    ).c_str( ),
                    resolver.get( )
                )
            );
auto_ptr<XPathEvaluator>   evaluator(XPathEvaluator::createEvaluator( ));
auto_ptr<XPathNSResolver>  resolver(evaluator->createNSResolver(animalList));
auto_ptr<XPathExpression>  xpath(
      evaluator->createExpression(
            fromNative("animalList/animal[child::name='Herby']").c_str( ),
            resolver.get( )
      ));

        // Evaluate the expression.
        XPathResult* result = 
            xpath->evaluate(
                doc, 
                XPathResult::ORDERED_NODE_ITERATOR_TYPE, 
                0
            );

        DOMNode* herby;
        if (herby = result->iterateNext( )) {
            animalList->removeChild(herby);
            herby->release( ); // optional.
        }

        // Construct a DOMWriter to save animals.xml.
        DOMPtr<DOMWriter> writer = 
            static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
        writer->setErrorHandler(&err);

        // Save animals.xml.
        LocalFileFormatTarget file("circus.xml");
        writer->writeNode(&file, *animalList);
    } catch (const DOMException& e) {
        cout << toNative(e.getMessage( )) << "\n";
        return EXIT_FAILURE;
    } catch (const XPathException &e) {
        cout << e.getString( ) << "\n";
        return EXIT_FAILURE;
    } catch (const exception& e) {
        cout << e.what( ) << "\n";
        return EXIT_FAILURE;
    }
}
开发者ID:arraytools,项目名称:C,代码行数:83,代码来源:14-24.cpp

示例5: main


//.........这里部分代码省略.........
    docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:NS1"), X("http://testclash.com"));

    //clash with standard prefix
    docFirstElementChildChild->setAttributeNS(X("http://testattr5.com"), X("po:attr10"), X("value"));

    doc->normalizeDocument();
    normalizer->serializeNode(doc);
    XERCES_STD_QUALIFIER cout << "\n\n";


    //2 prefix with the same uri
    docFirstElementChildChild = doc->createElementNS(X("http://www.uri1.com"),X("docEleChildChild6"));
    docFirstElementChild->appendChild(docFirstElementChildChild);
    docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:uri1"), X("http://www.uri1.com"));
    docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:uri1b"), X("http://www.uri1.com"));
    docFirstElementChildChild->setAttributeNS(X("http://www.uri1.com"), X("uri1:attr1"), X("value"));
    docFirstElementChildChild->setAttributeNS(X("http://www.uri1.com"), X("uri1b:attr2"), X("value"));
    doc->normalizeDocument();
    normalizer->serializeNode(doc);
    XERCES_STD_QUALIFIER cout << "\n\n";

    //check to see we use the nearest binding and for more inheritence
    DOMElement *docFirstElementChildChildChild = doc->createElementNS(X("http://www.uri1.com"),X("docEleChildChildChild"));
    docFirstElementChildChild->appendChild(docFirstElementChildChildChild);
    docFirstElementChildChild->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:nearerThanPo"), X("http://www.test.com"));
    docFirstElementChildChildChild->setAttributeNS(X("http://testattr.com"), X("attr2"), X("value"));
    docFirstElementChildChildChild->setAttributeNS(X("http://www.test.com"), X("attr1"), X("value"));
    doc->normalizeDocument();
    normalizer->serializeNode(doc);
    XERCES_STD_QUALIFIER cout << "\n\n";


    //NS1.1 stuff

    //test creating default prefix when NS1 has been set to ""
    noNamespaceEle->setAttributeNS(XMLUni::fgXMLNSURIName, X("xmlns:NS1"), X(""));
    DOMElement *noNamespaceChild = doc->createElementNS(X("http://testclash.com"),X("testing1.1Stuff"));
    noNamespaceEle->appendChild(noNamespaceChild);
    doc->normalizeDocument();
    normalizer->serializeNode(doc);

    noNamespaceChild = doc->createElementNS(X("http://testclash.com"),X("NS1:testing1.1Stuff"));
    noNamespaceEle->appendChild(noNamespaceChild);
    
    noNamespaceChild->setAttributeNS(X("http://www.someRandomUri.com"), X("attr"), X("value"));
    doc->normalizeDocument();
    normalizer->serializeNode(doc);


    //check error conditions
    XERCES_STD_QUALIFIER cout << "error conditions" << XERCES_STD_QUALIFIER endl;

    DOMConfiguration *conf = doc->getDOMConfig();
    conf->setParameter(XMLUni::fgDOMErrorHandler, normalizer);
    conf->setParameter(XMLUni::fgDOMNamespaces, true);

    DOMElement *level1Node = doc->createElement(X("level1Node"));
    docFirstElement->appendChild(level1Node);
    doc->normalizeDocument();

    docFirstElement->removeChild(level1Node);
    docFirstElement->setAttribute(X("level1Attr"), X("level1"));
    doc->normalizeDocument();
    docFirstElement->removeAttribute(X("level1Attr"));

    //cant check this as Xerces does not let us do it
    //    noNamespaceChild->setAttributeNS(X("http://www.someRandomUri.com"), X("xmlns"), X("value"));
    //    doc->normalizeDocument();



    //lets do a sanity test on a comment
    DOMComment *comment = doc->createComment(X("some comment"));
    docFirstElement->appendChild(comment);
    doc->normalizeDocument();
    normalizer->serializeNode(doc);

    conf->setParameter(XMLUni::fgDOMComments, false);
    docFirstElement->appendChild(comment);
    doc->normalizeDocument();
    normalizer->serializeNode(doc);


    //and on a CDATA
    DOMCDATASection *cData = doc->createCDATASection(X("some cdata"));
    docFirstElement->appendChild(cData);
    doc->normalizeDocument();
    normalizer->serializeNode(doc);

    conf->setParameter(XMLUni::fgDOMCDATASections, false);
    docFirstElement->appendChild(cData);
    doc->normalizeDocument();
    normalizer->serializeNode(doc);

    delete normalizer;
    delete tmpTrue;
    delete tmpFalse;

    return 0;
}
开发者ID:kanbang,项目名称:Colt,代码行数:101,代码来源:Normalizer.cpp

示例6: main

int main( )
{
    try {
        // Initialize Xerces and retrieve a DOMImplementation;
        // specify that you want to  use the Load and Save (LS)
        // feature
        XercesInitializer   init;
        DOMImplementation*  impl = 
            DOMImplementationRegistry::getDOMImplementation(
                fromNative("LS").c_str( )
            );
        if (impl == 0) {
            cout << "couldn't create DOM implementation\n";
            return EXIT_FAILURE;
        }

        // Construct a DOMBuilder to parse animals.xml.
        DOMPtr<DOMBuilder>  parser = 
            static_cast<DOMImplementationLS*>(impl)->
                createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);

        // Enable namespaces (not needed in this example)
        parser->setFeature(XMLUni::fgDOMNamespaces, true);

        // Register an error handler
        CircusErrorHandler  err;
        parser->setErrorHandler(&err);

        // Parse animals.xml; you can use a URL here 
        // instead of a file name
        DOMDocument* doc = 
            parser->parseURI("animals.xml");

        // Search for Herby the elephant: first, obtain a pointer 
        // to the "animalList" element.
        DOMElement*  animalList = doc->getDocumentElement( );
        if (animalList->getTagName( ) != fromNative("animalList")) {
            cout << "bad document root: " 
                 << toNative(animalList->getTagName( ))
                 << "\n";
            return EXIT_FAILURE;
        }

        // Next, iterate through the "animal" elements, searching
        // for Herby the elephant.
        DOMNodeList* animals = 
            animalList->getElementsByTagName(fromNative("animal").c_str( ));
        for ( size_t i = 0, 
                     len = animals->getLength( );
              i < len;
              ++i )
        {
            DOMElement* animal = 
              static_cast<DOMElement*>(animals->item(i));
            const XMLCh* name = getAnimalName(animal);
            if (name != 0 && name == fromNative("Herby")) {
                // Found Herby -- remove him from document.
                animalList->removeChild(animal);
                animal->release( ); // optional.
                break;
            }
        }

        // Construct a DOMWriter to save animals.xml.
        DOMPtr<DOMWriter> writer = 
            static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
        writer->setErrorHandler(&err);

        // Save animals.xml.
        LocalFileFormatTarget file("animals.xml");
        writer->writeNode(&file, *animalList);
    } catch (const SAXException& e) {
        cout << "xml error: " << toNative(e.getMessage( )) << "\n";
        return EXIT_FAILURE;
    } catch (const DOMException& e) {
        cout << "xml error: " << toNative(e.getMessage( )) << "\n";
        return EXIT_FAILURE;
    } catch (const exception& e) {
        cout << e.what( ) << "\n";
        return EXIT_FAILURE;
    }
}
开发者ID:arraytools,项目名称:C,代码行数:82,代码来源:14-10.cpp

示例7: handleDocument

// 2006/11/07
void handleDocument(DOMDocument* document, char* outputfile)
{
  if (document == NULL) {
    cerr << _PREFIX_ << "WARNING null XML Document\n";
    return;
  }
  DOMElement* docElement = NULL;
  docElement = document->getDocumentElement();

  if (docElement == NULL) {
    cerr << _PREFIX_ << "WARNING null XML Document Element\n";
    return;
  }


  DOMNodeList* sections = docElement->getElementsByTagName(XMLString::transcode("section"));
  int sCount = 0;
  int paragraphID = 1;

  for (unsigned int i = 0; i < sections->getLength(); i++) {
    int sectID = i+1;
    if (verbose) cerr << _PREFIX_ << "Section " << i;
    DOMElement* aSect = NULL;
    aSect = (DOMElement*)sections->item(i);
    string sectName = XMLString::transcode(((DOMElement*)aSect)->getAttribute(XMLString::transcode("name")));
    string analyze =
      XMLString::transcode(((DOMElement*)aSect)->getAttribute(XMLString::transcode("analyze")));
    if (verbose) cerr << " ['" << sectName << "'";
    // Ignore non affected sections 
    if ( ( analyze == "yes" ) ||
         ( sectName.length() == 0 ) ||
         ( affectedSections.find(sectName + "|") != string::npos )) {      
      
      if (verbose) cerr << " analyze=yes ";
      // Deal with unnamed and affected sections

      // create a stream
      aSect->normalize();
      stringstream text(XMLString::transcode(aSect->getTextContent()));

      if (verbose) {
        string temp(XMLString::transcode(aSect->getTextContent()));
        cerr << temp.length() << " charcters]\n" << _PREFIX_ << "           ";
      }

      aSect->removeChild(aSect->getFirstChild());

      vector<vector<string> > result;
      result = seg->segmentInVectors(text);

      for(vector<vector<string> >::iterator itp = result.begin(); 
          itp != result.end(); 
          itp++) {
        stringstream parID;
        parID << _ID_PREFIX_SECTION << sectID << _ID_PREFIX_PARAGRAPH << paragraphID++;
        sCount += addSegmentedParagraphToSection(*itp,aSect,parID.str().c_str());
      }
   
      if (verbose) cerr << endl;
    } else {
      if (verbose) cerr << " analyze=no]" << endl;
    }
  }

  if (stamp) stampDocument(docElement);

  /* SERIALIZE XML DOCUMENT */
  if (outputfile == NULL) xmlInterface->serializeTo(document);
  else xmlInterface->serializeTo(document,outputfile);

  if (verbose) cerr << _PREFIX_ << "Segmented in " << sCount << " sentences." << endl;
}
开发者ID:lgwizme,项目名称:macaon,代码行数:73,代码来源:main.cpp


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