Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
    Xml *pXml = new Xml();

    xmlNode *pRootNode = pXml->loadFile("TestXPath.xml");

    xmlNode *pNode = pXml->getNodeByXPath("/Root/bookstore/book[2]/title");

    int rt = 0;
    std::string value;

    if (NULL != pNode) {
        pXml->getNodeValue(pNode, &value);
        std::cout << value << std::endl;
    }

    pNode = pXml->getChildNodeByNodeName(pRootNode, "bookstore");

    pNode = pXml->getNodeByXPath(pNode, "book[1]/title");

    if (NULL != pNode) {
        pXml->getNodeValue(pNode, &value);
        std::cout << value << std::endl;
    }

    pNode = pXml->getNodeByXPath(pNode, "/Root/bookstore/book[1]/title");

    if (NULL != pNode) {
        pXml->getNodeValue(pNode, &value);
        std::cout << value << std::endl;
    }

    delete pXml;

    return 0;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
    if (2 != argc) {
        usage(argv[0]);
        exit(1);
    }

    std::string cmd = argv[1];

    if (cmd != "clean" && cmd != "gen") {
        usage(argv[0]);
        exit(1);
    }

    int rt = 0;

    Xml *pXml = new Xml();

    xmlNode *pRoot = pXml->loadFile("TestConf.xml");

    if (NULL == pRoot) {
        ERROR_LOG("load configuration from TestConf.xml failed");
        exit(1);
    }

    std::string dataRoot;

    rt = pXml->getNodeValueByXPath("/TestConf/MU/FileSystemRoot", &dataRoot);

    if (-1 == rt) {
        ERROR_LOG("parse data root path from TestConf.xml failed");
        exit(1);
    }

    delete pXml;
    pXml = NULL;

    DataGen *pDataGen = new DataGen(dataRoot);

    if (cmd == "clean") {
        rt = pDataGen->clean();

        if (-1 == rt) {
            ERROR_LOG("clean data failed");
            exit(1);
        }

    } else {
        rt = pDataGen->gen();

        if (-1 == rt) {
            ERROR_LOG("gen data failed");
            exit(1);
        }
    }

    printf("success!\n");

    return 0;
}