Xerces C ++ способ записать обновленный XML в строку - PullRequest
0 голосов
/ 12 марта 2019

Я пытаюсь проанализировать файл XMl, расположенный в строке, и обновить некоторые атрибуты в XML. Я использую парсер xerces c ++ для того же самого и использую MemBufInputSource и parse для того же самого.

 cout << "Got the string object" << endl;
        cout << "The XML is: " << str.str() << endl;
        string registrationRequest=str.str();


        XMLPlatformUtils::Initialize();
        XercesDOMParser *parser = new XercesDOMParser;
        parser->setValidationScheme(XercesDOMParser::Val_Never);
        parser->setDoNamespaces(false);
        parser->setDoSchema(false);

    MemBufInputSource registrationRequest_buf((const XMLByte*)registrationRequest.c_str(),
                        registrationRequest.size(), "dummy", false);

        parser->parse(registrationRequest_buf);
        DOMDocument *doc = parser->getDocument();
        DOMElement* elementRoot = doc->getDocumentElement();
        char *RootName = XMLString::transcode(elementRoot->getTagName());
        XMLCh *ns = XMLString::transcode("xmlns");
        XMLCh *val = XMLString::transcode("Some Value that I want to update");
        elementRoot->removeAttribute(ns);
        elementRoot->setAttribute(ns, val);

        DOMNodeList* children = elementRoot->getChildNodes();
        const  XMLSize_t nodeCount = children->getLength();
        val = XMLString::transcode("");
        for( XMLSize_t xx = 0; xx < nodeCount; ++xx )
        {
         DOMNode* currentNode = children->item(xx);
            if( currentNode->getNodeType() &&  // true is not NULL
             currentNode->getNodeType() == DOMNode::ELEMENT_NODE ) // is element
             {
                DOMElement* currentElement
                                        = dynamic_cast< xercesc::DOMElement* >( currentNode );
                currentElement->setAttribute(ns, val);
             }
        }

Может кто-нибудь помочь, пожалуйста, как мне написать обратно мой обновленный xml в строку.

...