コード例 #1
0
ファイル: XMLFile.cpp プロジェクト: 03050903/Urho3D
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.");
    }
}
コード例 #2
0
ファイル: XMLElement.cpp プロジェクト: rokups/Urho3D
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);
}
コード例 #3
0
ファイル: XMLElement.cpp プロジェクト: rokups/Urho3D
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);
}
コード例 #4
0
ファイル: XMLElement.cpp プロジェクト: rokups/Urho3D
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);
}
コード例 #5
0
ファイル: XMLElement.cpp プロジェクト: zhzhxtrrk/Urho3D
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;
}
コード例 #6
0
ファイル: XMLElement.cpp プロジェクト: rokups/Urho3D
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;
}