在解析xml文件时用了Xerces-C++库,使用这个库来保存xml文件后用windows的记事本打开不能自动换行,修改或者查看xml文件起来不方便。
    有谁对Xerces-C++库比较精通,知道使用哪个函数可以直接输出回车换行符,让windows的记事本打开会自动换行。不要说使用别的工具(如ue)来打开xml文件,不能这么解决。

解决方案 »

  1.   

    你加内容会破坏XML文件结构的。
    如果你自己加了内容,专业工具打开的时候,你就会碰到麻烦了。应该是编辑工具来适应XML,而不是XML适应编辑工具。
      

  2.   

    try 
    {
    XMLPlatformUtils::Initialize();
    }
    catch (const XMLException& toCatch) 
    {
    return -1;
    } XMLCh str[10]; XMLString::transcode("Core",str,9);
    DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(str);
    XMLString::transcode("Test",str,9);
    DOMDocument* doc = impl->createDocument(0, str, 0);
    XMLString::transcode("begin",str,9);
    DOMElement* node = doc->createElement(str);
    XMLString::transcode("Child1",str,9);
    DOMElement* node1 = doc->createElement(str);
    XMLString::transcode("Child2",str,9);
    DOMElement* node2 = doc->createElement(str);
    DOMElement* root = doc->getDocumentElement(); root->appendChild(node); XMLCh *value = XMLString::transcode("20130101");
    XMLCh *attri = XMLString::transcode("num"); node1->setAttribute(attri, value);
    node2->setAttribute(attri, value); node->appendChild(node1);
    node->appendChild(node2);
    //XMLString::transcode("Text",str,9);
    //DOMText * dText = doc->createTextNode(str);
    //node1->appendChild(dText); DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
    DOMLSSerializer*  serial = ((DOMImplementationLS*)impl)->createLSSerializer();
            //设置serial属性使生成的xml文件自动换行
    serial->getDomConfig()->setParameter(XMLString::transcode("format-pretty-print"), true); serial->setNewLine(XMLString::transcode("\n"));
    LocalFileFormatTarget *ptrTar = new LocalFileFormatTarget("./xmlWithLine.xml"); output->setByteStream(ptrTar); serial->write(doc, output);
    doc->release();
    delete impl;