C++ (Cpp) TiXmlElement Examples

C++ (Cpp) TiXmlElement - 30 examples found. These are the top rated real world C++ (Cpp) examples of TiXmlElement extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
bool CAddon::LoadSettings(bool bForce /* = false*/)
{
    if (m_settingsLoaded && !bForce)
        return true;
    if (!m_hasSettings)
        return false;
    CStdString addonFileName = URIUtils::AddFileToFolder(m_props.path, "resources/settings.xml");

    if (!m_addonXmlDoc.LoadFile(addonFileName))
    {
        if (CFile::Exists(addonFileName))
            CLog::Log(LOGERROR, "Unable to load: %s, Line %d\n%s", addonFileName.c_str(), m_addonXmlDoc.ErrorRow(), m_addonXmlDoc.ErrorDesc());
        m_hasSettings = false;
        return false;
    }

    // Make sure that the addon XML has the settings element
    TiXmlElement *setting = m_addonXmlDoc.RootElement();
    if (!setting || strcmpi(setting->Value(), "settings") != 0)
    {
        CLog::Log(LOGERROR, "Error loading Settings %s: cannot find root element 'settings'", addonFileName.c_str());
        return false;
    }
    SettingsFromXML(m_addonXmlDoc, true);
    LoadUserSettings();
    m_settingsLoaded = true;
    return true;
}
Example #2
0
bool XMLList::_Parse(TiXmlDocument& _xmlDoc)
{
    TiXmlElement* tiRoot = _xmlDoc.RootElement();
    if (!tiRoot)
    {
        return false;
    }
    std::string sRootName = tiRoot->Value();
    if (sRootName != XMLLIST_ROOT )
    {
        return false;
    }

    TiXmlNode * tiFirst = tiRoot->FirstChild(XMLLIST_XML);
    if(tiFirst == NULL)
    {
        return false;
    }
    for (TiXmlElement* indexElement = tiFirst->ToElement();
            indexElement != NULL;
            indexElement = indexElement->NextSiblingElement())
    {
        XMLFileObject* pXML = new XMLFileObject;
        if(Helper::GetXmlStrAttributeA(indexElement, ID_OBJECT, pXML->Id)
                && Helper::GetXmlStrAttributeA(indexElement, TYPE_OBJECT, pXML->Type)
                && Helper::GetXmlStrAttributeA(indexElement, XMLLIST_PATH, pXML->Path))
        {
            m_mapXMLList[pXML->Id] = pXML;
        }
    }
    return true;
}
Example #3
0
//报文解析
bool XMLgetReturnData(const char *utf8xmlin,char*utf8xmlout)
{
    //放在栈里 内存不会泄露
    TiXmlDocument myDocument;
    myDocument.Parse(utf8xmlin);

    TiXmlElement *pRootEle = myDocument.RootElement();
    if (NULL==pRootEle)
    {
        printf("XMLgetReturnData XML出错\n");
        return false;
    }

    TiXmlElement *pNodeRow = NULL;
    TiXmlElement *pNodeData = NULL;

    for(pNodeRow = pRootEle; pNodeRow; pNodeRow = pNodeRow->NextSiblingElement())
    {
        pNodeData = NULL;
        if(ReadQueryNodeText(pNodeRow,pNodeData,"bms1:return",utf8xmlout,XMLRW_MAX_STR,false))
        {
            //printf("bms1:return=%s\n",returnstr);
            break ;
        }
    }
    return true;
}
Example #4
0
int main()
{
    TiXmlDocument doc;
    doc.Parse(testXml.c_str());

    TiXmlNode* node = 0;
    TiXmlElement* requestElement = 0;

    node = doc.FirstChild("request");
    assert(node);
    requestElement = node->ToElement();
    assert(requestElement);

    string typeInfo(requestElement->Attribute("type"));

    if (typeInfo == "heartbeat")
    {
        cout << "Hey heartbeat" << endl;
        boost::replace_first(testXml,"request type=\"heartbeat\"", "request");
    }

    cout << testXml << endl;

    return 0;
}
//---------------------------------------------------------
int ofxXmlSettings::writeAttribute(const string& tag, const string& attribute, const string& valueString, int which) {
    vector<string> tokens = tokenize(tag,":");
    TiXmlHandle tagHandle = storedHandle;
    for (int x = 0; x < tokens.size(); x++) {
        if (x == 0)
            tagHandle = tagHandle.ChildElement(tokens.at(x), which);
        else
            tagHandle = tagHandle.FirstChildElement(tokens.at(x));
    }

    int ret = 0;
    if (tagHandle.ToElement()) {
        TiXmlElement* elem = tagHandle.ToElement();
        elem->SetAttribute(attribute, valueString);

        // Do we really need this?  We could just ignore this and remove the 'addAttribute' functions...
        // Now, just get the ID.
        int numSameTags;
        TiXmlElement* child = ( storedHandle.FirstChildElement( tokens.at(0) ) ).ToElement();
        for (numSameTags = 0; child; child = child->NextSiblingElement( tokens.at(0) ), ++numSameTags) {
            // nothing
        }
        ret = numSameTags;
    }
    return ret;
}
//---------------------------------------------------------
bool ofxXmlSettings::readDoubleAttribute(const string& tag, const string& attribute, double& outValue, int which) {

    TiXmlElement* elem = getElementForAttribute(tag, which);
    if (elem)
        return (elem->QueryDoubleAttribute(attribute, &outValue) == TIXML_SUCCESS);
    return false;
}