void XMLDocumentWrapperTestCase::testParse()
{
    std::string sXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                       "<root>\n"
                       "\t<global>\n"
                       "\t\t<general>\n"
                       "\t\t\t<dict id=\"id_attr_value\">dict_value</dict>\n"
                       "\t\t</general>\n"
                       "\t</global>\n"
                       "</root>\n\n";
    XMLDocumentWrapper xmlDoc;
    try
    {
        xmlDoc.parse(sXml);
    }
    catch(const BadXmlFormatException& )
    {
        CPPUNIT_ASSERT(false);
    }

    XMLNodeWrapperPtr firstNode = xmlDoc.firstNode();
    CPPUNIT_ASSERT(firstNode;
    CPPUNIT_ASSERT_EQUAL(std::string("root"), std::string(firstNode->getName()));

    string sPrint;
    xmlDoc.print(sPrint);
    CPPUNIT_ASSERT_EQUAL(sXml, sPrint);
}
Example #2
0
void XMLConfigurator::load(XMLNodeWrapperPtr& pNode, Configurator::ConfMap& conf)
{
    XMLNodeWrapperPtr pChild = pNode->firstNode();
    if (pChild.isNull())
    {
        Configurator c(conf, Configurator::TO_CONF);
        string sValue = pNode->getValue();
        c.configure((const string&)pNode->getName(), 
                    sValue, (const string&)_T(""));
        conf = c.getMap();
    }
    else if (pChild->nextSibling().isNull() 
             && pChild->type() == XMLDocumentWrapper::NODE_DATA)
    {
        Configurator c(conf, Configurator::TO_CONF);
        string sValue = pChild->getValue();
        c.configure((const string&)pNode->getName(), 
                    sValue, (const string&)_T(""));
        conf = c.getMap();
    }
    else 
    {
        Configurator::ConfMap confMap;
        for (XMLNodeWrapperPtr pSubNode = pNode->firstNode();
             pSubNode.isNotNull(); pSubNode = pSubNode->nextSibling())
        {
            load(pSubNode, confMap);
        }

        if (strCompareNoCase(pNode->getName(), CONFIGURE_TAG_NAME))
        {
            Configurator c(conf, Configurator::TO_CONF);
            c.configure(pNode->getName(), confMap);
            conf = c.getMap();
        }
        else 
        {
            conf = confMap;
        }
    }
}
void TrecDocumentProcessorTestCase::makeAnswer(const std::string& str, Answer& ans)
{
    XMLDocumentWrapper xmlDoc;
    xmlDoc.parse(str);
    
    for (XMLNodeWrapperPtr pDocNode = xmlDoc.firstNode();
         pDocNode; pDocNode = pDocNode->nextSibling())
    {
        for (XMLNodeWrapperPtr pChildNode = pDocNode->firstNode();
             pChildNode; pChildNode = pChildNode->nextSibling())
        {
            ans.push_back(make_pair(pChildNode->getName(), pChildNode->getValue()));
        }
    }
}