Making Xerces parse a string instead of a file

后端 未结 3 1841
情深已故
情深已故 2020-12-14 18:36

I know how to create a complete dom from an xml file just using XercesDOMParser:

xercesc::XercesDOMParser parser = new xercesc::XercesDOMParser();
parser->         


        
相关标签:
3条回答
  • 2020-12-14 19:32

    Im doing it another way. If this is incorrect, please tell me why. It seems to work. This is what parse expects:

    DOMDocument* DOMLSParser::parse(const DOMLSInput * source )
    

    So you need to put in a DOMLSInput instead of a an InputSource:

    xercesc::DOMImplementation * impl = xercesc::DOMImplementation::getImplementation();
    xercesc::DOMLSParser *parser = (xercesc::DOMImplementationLS*)impl)->createLSParser(xercesc::DOMImplementation::MODE_SYNCHRONOUS, 0);
    xercesc::DOMDocument *doc;
    
    xercesc::Wrapper4InputSource source (new xercesc::MemBufInputSource((const XMLByte *) (myxml.c_str()), myxml.size(), "A name");
    parser->parse(&source);
    
    0 讨论(0)
  • 2020-12-14 19:36

    Use the following overload of XercesDOMParser::parse():

    void XercesDOMParser::parse(const InputSource& source);
    

    passing it a MemBufInputSource:

    MemBufInputSource src((const XMLByte*)myxml.c_str(), myxml.length(), "dummy", false);
    parser->parse(src);
    
    0 讨论(0)
  • 2020-12-14 19:40

    Create a MemBufInputSource and parse that:

    xercesc::MemBufInputSource myxml_buf(myxml.c_str(), myxml.size(),
                                         "myxml (in memory)");
    parser->parse(myxml_buf);
    
    0 讨论(0)
提交回复
热议问题