TinyXML2 学习

http://blog.csdn.net/cen616899547/article/details/9187687


tinyxml2::XMLDocument objXMLRoot;
    XMLElement* pElemDeviceInfo = objXMLRoot.NewElement("device_info");
    objXMLRoot.InsertEndChild(pElemDeviceInfo);


    INSERT_XML_PARAM(pElemDeviceInfo, "PID", m_strPID.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "ProduceDate", m_strProduceDate.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "SN", m_strSN.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "IRoIP", m_strIRoIPEnable.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "SoIP", m_strSoIPEnable.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "VISelect", m_strVISelect.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "AISelect", m_strAISelect.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "VI", m_strVI.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "AI", m_strAI.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "VITiming", m_strVITiming.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "AIInfo", m_strAIInfo.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "ENCBig", m_strVENCBig.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "ENCSmall", m_strVENCSmall.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "HDMIEDID", m_strLoopHDMIEDID.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "VGAEDID", m_strLoopVGAEDID.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "MasterLoop", m_strMasterLoop.c_str());
    INSERT_XML_PARAM(pElemDeviceInfo, "ForceOutput", m_strForceOutput.c_str());


    XMLPrinter objStreamer;
    objXMLRoot.Print( &objStreamer );
    printf( "%s", objStreamer.CStr() );
    std::string strDeviceInfo = objStreamer.CStr();
#define INSERT_XML_PARAM(xml_node, name, value)     \
    do { XMLElement* pElemLabel = objXMLRoot.NewElement("label");\
        xml_node->InsertEndChild(pElemLabel);\
        pElemLabel->SetAttribute("name", name);\
        XMLText *pText = objXMLRoot.NewText(value);\
        pElemLabel->InsertFirstChild(pText);\
    } while (0);


结果:
<device_info>
    <label name="PID">MX153-96F875E58332</label>
    <label name="ProduceDate">20140228</label>
    <label name="SN">1</label>
    <label name="IRoIP">enable</label>
    <label name="SoIP">enable</label>
    <label name="VISelect">unknown</label>
    <label name="AISelect">unknown</label>
    <label name="VI">unknown</label>
    <label name="AI">unknown</label>
    <label name="VITiming">unknown</label>
    <label name="AIInfo">unknown</label>
    <label name="ENCBig">unknown</label>
    <label name="ENCSmall">unknown</label>
    <label name="HDMIEDID">not attached</label>
    <label name="VGAEDID">unknown</label>
    <label name="MasterLoop">unknown</label>
    <label name="ForceOutput">unknown</label>
</device_info>

你可能感兴趣的:(TinyXML2 学习)