void XMLFile::Patch(XMLElement patchElement) { pugi::xml_node root = pugi::xml_node(patchElement.GetNode()); for (pugi::xml_node::iterator patch = root.begin(); patch != root.end(); patch++) { pugi::xml_attribute sel = patch->attribute("sel"); if (sel.empty()) { URHO3D_LOGERROR("XML Patch failed due to node not having a sel attribute."); continue; } // Only select a single node at a time, they can use xpath to select specific ones in multiple otherwise the node set becomes invalid due to changes pugi::xpath_node original = document_->select_single_node(sel.value()); if (!original) { URHO3D_LOGERRORF("XML Patch failed with bad select: %s.", sel.value()); continue; } if (strcmp(patch->name(), "add") == 0) PatchAdd(*patch, original); else if (strcmp(patch->name(), "replace") == 0) PatchReplace(*patch, original); else if (strcmp(patch->name(), "remove") == 0) PatchRemove(original); else URHO3D_LOGERROR("XMLFiles used for patching should only use 'add', 'replace' or 'remove' elements."); } }
float XPathQuery::EvaluateToFloat(const XMLElement& element) const { if (!query_ || ((!element.GetFile() || !element.GetNode()) && !element.GetXPathNode())) return 0.0f; const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node() : pugi::xml_node(element.GetNode()); return (float)query_->evaluate_number(node); }
bool XPathQuery::EvaluateToBool(const XMLElement& element) const { if (!query_ || ((!element.GetFile() || !element.GetNode()) && !element.GetXPathNode())) return false; const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node() : pugi::xml_node(element.GetNode()); return query_->evaluate_boolean(node); }
XPathResultSet XPathQuery::Evaluate(const XMLElement& element) const { if (!query_ || ((!element.GetFile() || !element.GetNode()) && !element.GetXPathNode())) return XPathResultSet(); const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node() : pugi::xml_node(element.GetNode()); pugi::xpath_node_set result = query_->evaluate_node_set(node); return XPathResultSet(element.GetFile(), &result); }
String XPathQuery::EvaluateToString(XMLElement element) const { if (!query_ || ((!element.GetFile() || !element.GetNode()) && !element.GetXPathNode())) return String::EMPTY; const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node(): pugi::xml_node(element.GetNode()); String result; result.Reserve(query_->evaluate_string(0, 0, node)); // First call get the size query_->evaluate_string(const_cast<pugi::char_t*>(result.CString()), result.Capacity(), node); // Second call get the actual string return result; }
ea::string XPathQuery::EvaluateToString(const XMLElement& element) const { if (!query_ || ((!element.GetFile() || !element.GetNode()) && !element.GetXPathNode())) return EMPTY_STRING; const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node() : pugi::xml_node(element.GetNode()); ea::string result; // First call get the size result.reserve((unsigned) query_->evaluate_string(nullptr, 0, node)); // Second call get the actual string query_->evaluate_string(const_cast<pugi::char_t*>(result.c_str()), result.capacity(), node); return result; }