Skip to content

Instantly share code, notes, and snippets.

@joshuajnoble
Created August 13, 2013 13:22
Show Gist options
  • Save joshuajnoble/6221014 to your computer and use it in GitHub Desktop.
Save joshuajnoble/6221014 to your computer and use it in GitHub Desktop.
fixing error in ofXml.cpp
string ofXml::getAttribute(const string& path) const {
Poco::XML::Node *e;
if(element) {
if(path.find("[@") == string::npos) {
// we need to create a proper path
string attributePath = "[@" + path + "]";
e = element->getNodeByPath(attributePath);
} else {
e = element->getNodeByPath(path);
}
} else {
ofLogWarning("ofXml") << "getAttribute(): no element set yet";
return "";
}
if(e) {
return e->getNodeValue(); // this will be the value of the attribute
}
return "";
}
bool ofXml::removeAttribute(const string& path)
{
Poco::XML::Element *e;
if(element) {
// you're *not* using a path
if(path.find("[@") == string::npos) {
e = element;
} 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(int i = 0; i < (int)map->length(); i++) {
e->removeAttribute(map->item(i)->nodeName());
}
map->release();
return true;
}
return false;
}
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(int i = 0; i < (int)map->length(); i++) {
e->removeAttribute(map->item(i)->nodeName());
}
map->release();
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment