Ejemplo n.º 1
0
bool ofXml::removeAttributes(const string& path) 
{
    Poco::XML::Element *e;
    if(element) {
        if(path.find("[@") == string::npos) {
            // we need to create a proper path
            string attributePath = "[@" + path + "]";
            e = (Poco::XML::Element*) element->getNodeByPath(attributePath);
        } else {
            e = (Poco::XML::Element*) element->getNodeByPath(path);
        }

    } else {
        ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
        return false;
    }
    
    if(e) {
        Poco::XML::NamedNodeMap *map = e->attributes();
        
        for(unsigned long i = 0; i < map->length(); i++) {
            e->removeAttribute(map->item(i)->nodeName());
        }
        
        map->release();
        return true;
    }
    return false;
}
Ejemplo n.º 2
0
bool ofXml::removeAttribute(const string& path) 
{

    string attributeName, pathToAttribute;

    Poco::XML::Element *e;
    if(element) {
        
        bool hasPath = false;

        // you can pass either /node[@attr] or just attr
        if(path.find("[@") != string::npos)
        {
            int attrBegin = path.find("[@");
            int start = attrBegin + 2;
            int end = path.find("]", start);
            attributeName = path.substr( start, end - start );
            pathToAttribute = path.substr(0, attrBegin);
            hasPath = true;
        }
        else
        {
            attributeName = path;
        }
        
        if(hasPath) {
            e = (Poco::XML::Element*) element->getNodeByPath(pathToAttribute);
        } else {
            e = element;
        }

    } else {
        ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
        return false;
    }
    
    if(e) {
        Poco::XML::NamedNodeMap *map = e->attributes();
        
		for(unsigned long i = 0; i < map->length(); i++) {
            if(map->item(i)->nodeName() == attributeName) {
                e->removeAttribute(map->item(i)->nodeName());
            }
        }
        
        map->release();
        return true;
    }
    return false;
}
Ejemplo n.º 3
0
bool ofXml::removeAttributes()
{

    if(element) {
        Poco::XML::NamedNodeMap *map = element->attributes();
        
        for(unsigned long i = 0; i < map->length(); i++) {
            element->removeAttribute(map->item(i)->nodeName());
        }
        
        map->release();
        return true;
    }
    ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
    return false;

}