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


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

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


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

示例1: main

/**
 * Main routine that utilizes Xercesc module to create a DOM object in memory 
 * and prints out the resultant DOM structure 
 * @param argC    number of command line args 
 * @param argV    name of command line args 
 * @return        0 if no errors occurred 
 */
int main(int argC, char*argv[]) {
    // Initialize the XML4C2 system.
    try {
        XMLPlatformUtils::Initialize();
} catch (const XMLException& toCatch) {
    char *pMsg = XMLString::transcode(toCatch.getMessage());
    XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n" << "  Exception message:" << pMsg;
    XMLString::release(&pMsg);
    return 1;
}

    // Watch for special case help request
    int errorCode = 0;
    if (argC > 1) {
        XERCES_STD_QUALIFIER
        cout << "\nUsage:\n"
                "    CreateDOMDocument\n\n"
                "This program creates a new DOM document from scratch in memory.\n"
                "It then prints the count of elements in the tree.\n" << XERCES_STD_QUALIFIER
                endl;
        errorCode = 1;
    }
    if (errorCode) {
        XMLPlatformUtils::Terminate();
        return errorCode;
    }


    DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));

    if (impl != NULL) {
        try {
            // create a DomDocument instance
            DOMDocument* doc = impl->createDocument(
                    0, // root element namespace URI.
                    X("TheHood"), // root element name
                    0); // document type object (DTD).

            // create root attribute nodes
            DOMAttr* woop_atr = doc->createAttribute(X("WOOP"));
            woop_atr->setValue(X("DANG"));
            DOMAttr* fiyah_atr = doc->createAttribute(X("FIYAH"));
            fiyah_atr->setValue(X("hot"));
            DOMAttr* hungry_atr = doc->createAttribute(X("hungry"));
            hungry_atr->setValue(X("starving"));

            // create root element
            DOMElement* rootElem = doc->getDocumentElement();
            // set root attrs
            rootElem->setAttributeNode(woop_atr);
            rootElem->setAttributeNode(fiyah_atr);
            rootElem->setAttributeNode(hungry_atr);

            //create root child elements
            DOMElement* gangElem = doc->createElement(X("gang"));
            rootElem->appendChild(gangElem);
            DOMText* gangDataVal = doc->createTextNode(X("YoungThugz"));
            gangElem->appendChild(gangDataVal);
            gangElem->setAttribute(X("hardness"), X("rock"));

            //create gang attr nodes
            DOMAttr* members_atr = doc->createAttribute(X("members"));
            members_atr->setValue(X("500"));
            DOMAttr* color_atr = doc->createAttribute(X("color"));
            color_atr->setValue(X("magenta"));
            // set gang attr
            gangElem->setAttributeNode(members_atr);
            gangElem->setAttributeNode(color_atr);
            // create gang elem children
            DOMElement* piruElem = doc->createElement(X("piru"));
            piruElem->setNodeValue(X("w"));
            DOMElement* cripElem = doc->createElement(X("crip"));
            cripElem->setNodeValue(X("t"));
            DOMElement* trgElem = doc->createElement(X("trg"));
            trgElem->setNodeValue(X("o"));
            // append gang elem children
            gangElem->appendChild(piruElem);
            gangElem->appendChild(cripElem);
            gangElem->appendChild(trgElem);

            DOMElement* turfElem = doc->createElement(X("turf"));
            rootElem->appendChild(turfElem);
            turfElem->setAttribute(X("idea"), X("great"));
            DOMText* turfDataVal = doc->createTextNode(X("West Side Projects"));
            turfElem->appendChild(turfDataVal);

            DOMElement* cliqueElem = doc->createElement(X("clique"));
            rootElem->appendChild(cliqueElem);
            DOMText* cliqueDataVal = doc->createTextNode(X("Balla$"));
            cliqueElem->appendChild(cliqueDataVal);
            cliqueElem->setAttribute(X("Comradery"), X("tight"));

            DOMElement* sideElem = doc->createElement(X("side"));
//.........这里部分代码省略.........
开发者ID:kidculli,项目名称:XMLParser,代码行数:101,代码来源:main.cpp


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