Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xerces-C++;Read&;编写UTF-8文档 在使用XeRCEC++读取和保存XML文档时,我有困难从UTF-16切换到UTF-8。(使用V3.1.1)_C++_Xml_Utf 8_Xerces C - Fatal编程技术网

Xerces-C++;Read&;编写UTF-8文档 在使用XeRCEC++读取和保存XML文档时,我有困难从UTF-16切换到UTF-8。(使用V3.1.1)

Xerces-C++;Read&;编写UTF-8文档 在使用XeRCEC++读取和保存XML文档时,我有困难从UTF-16切换到UTF-8。(使用V3.1.1),c++,xml,utf-8,xerces-c,C++,Xml,Utf 8,Xerces C,我试图通过TCHAR(wchar)读取UTF-8xml字符串,但它总是无法加载,我也不知道为什么。我认为这是因为我如何处理TCHAR(代码是我所做工作的总结): reader->impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS")); reader->parser = ((DOMImplementationLS*)impl)->cre

我试图通过TCHAR(wchar)读取UTF-8xml字符串,但它总是无法加载,我也不知道为什么。我认为这是因为我如何处理TCHAR(代码是我所做工作的总结):

    reader->impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
    reader->parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);

    if (reader->parser->getDomConfig()->canSetParameter(XMLUni::fgDOMValidate, false))
            reader->parser->getDomConfig()->setParameter(XMLUni::fgDOMValidate, false);
    if(reader->parser->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTWhitespaceInElementContent,false))
            reader->parser->getDomConfig()->setParameter(XMLUni::fgDOMWRTWhitespaceInElementContent,false);

    //create input dominputsource from the XML string
    DOMLSInput* dis = NULL;
    XMLCh * xmlch_string =  transcode(xml_string);
    unsigned int str_len  = XMLString::stringLen(xmlch_string);
    XMLByte * bytes_of_string = (XMLByte *) xmlch_string; 
    DOMLSInput* dis = new Wrapper4InputSource(
                new MemBufInputSource(bytes_of_string, 
                                4*str_len,
                                TEXT("buffer_for_reading_xml")));

    try {
            reader->document = reader->parser->parse(dis); // document = XERCES_CPP_NAMESPACE::DOMDocument*
    }catch (...) {
            cout << "Exception parsing the document. \n";
            return false;
    }
    XERCES_CPP_NAMESPACE::DOMDocument*  doc;
    TCHAR *         str             = NULL;
    bool            result          = false;
    XMLWriter *     writer          = NULL;
    size_t          len             = 0;
    XMLCh *         xmlch_string    = NULL;

    writer->impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
    writer->m_Document = impl->createDocument();

    writer->setSystem(m_System);
    doc = writer->m_Document;
    result = writer->write(doc, roots);

    ////////////////////////////////////
    // One of the write functions of writer->write:

    DOMElement*         rootNode;
    const TCHAR *   checkout_id;
    rootNode = doc->createElement(ROOT_TAG);
    try{doc->appendChild(rootNode);}
    catch(...){return false;}

    rootNode->setAttribute(XML_ID_ATTRIBUTE, transcode(m_System->system_id()));

    checkout_id = getSystemCheckoutId();
    rootNode->setAttribute(XML_CHECKOUT_ID_ATTRIBUTE, transcode(checkout_id));
    //add xml version to the root
    rootNode->setAttribute(XML_FORMAT_VERSION_ATTRIBUTE, g_FORMAT_VERSION);
    ////////////////////////////////////
    try
    {
        // get a serializer, an instance of DOMWriter
        /*while new class DOMLSSerializer is used here instead of DOMWriter;
        Difference between them is that the initialisation of pointer and the output */ 
        XMLCh tempStr[256];
        XMLString::transcode("LS", tempStr, 99);
        DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
        DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
        

        // set feature if the serializer supports the feature/mode
        if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTSplitCdataSections, false))
            theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTSplitCdataSections, false);

        if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
            theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);

        // write to a XMLCh string 
        xmlch_string = theSerializer->writeToString(doc);