本文整理汇总了C++中arabica::xpath::XPath::evaluate_expr方法的典型用法代码示例。如果您正苦于以下问题:C++ XPath::evaluate_expr方法的具体用法?C++ XPath::evaluate_expr怎么用?C++ XPath::evaluate_expr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arabica::xpath::XPath
的用法示例。
在下文中一共展示了XPath::evaluate_expr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("four")));
chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("five")));
numbers_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
numbers_.appendChild(numbers_.createElement(SA::construct_from_utf8("doc")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("1")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("2")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("3")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("4")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("5")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("6")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("7")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("8")));
numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("9")));
std::cout << document_ << std::endl;
std::cout << numbers_ << std::endl;
std::cout << chapters_ << std::endl;
if (true) {
using namespace Arabica::XPath;
using namespace Arabica::DOM;
XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("//*"), document_);
for(int i = 0; i < result.asNodeSet().size(); i++) {
Node<string_type, string_adaptor> node = result.asNodeSet()[i];
std::string xpathExpr = uscxml::DOMUtils::xPathForNode(node);
if (xpathExpr.size()) {
XPathValue<string_type, string_adaptor> innerResult = parser.evaluate(xpathExpr, document_);
assert(innerResult.asNodeSet().size() > 0);
assert(innerResult.asNodeSet().size() == 1);
assert(innerResult.asNodeSet()[0] == node);
} else {
assert(node.getNodeType() != Node_base::ELEMENT_NODE);
}
}
}
if (false) {
using namespace Arabica::XPath;
StringVariableResolver svr;
svr.setVariable(SA::construct_from_utf8("index"), SA::construct_from_utf8("1"));
parser.setVariableResolver(svr);
XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("/root/*[@two = $index]"), document_);
assert(NODE_SET == result.type());
assert(element2_ == result.asNodeSet()[0]);
parser.resetVariableResolver();
} // test18
if (false) {
using namespace Arabica::XPath;
XPathExpression<string_type, string_adaptor> xpath = parser.compile(SA::construct_from_utf8("root/*[position() = 2]"));
XPathValue<string_type, string_adaptor> result = xpath.evaluate(document_);
assert(NODE_SET == result.type());
assert(1 == result.asNodeSet().size());
Arabica::DOM::Node<string_type, string_adaptor> n = result.asNodeSet()[0];
assert(element2_ == n);
} // test19
if (false) {
using namespace Arabica::XPath;
Arabica::DOM::DocumentFragment<string_type, string_adaptor> frag = document_.createDocumentFragment();
frag.appendChild(document_.createElement(SA::construct_from_utf8("foo")));
NodeSetVariableResolver svr;
NodeSet<string_type, string_adaptor> ns;
ns.push_back(frag);
svr.setVariable(SA::construct_from_utf8("fruit"), ns);
parser.setVariableResolver(svr);
XPathValue<string_type, string_adaptor> result = parser.evaluate_expr(SA::construct_from_utf8("$fruit/foo|/root/child3"), document_);
assert(NODE_SET == result.type());
assert(2 == result.asNodeSet().size());
assert(element3_ == result.asNodeSet()[0]);
} // testUnion11
if (false) {
using namespace Arabica::XPath;
XPathValue<string_type, string_adaptor> result = parser.evaluate_expr(SA::construct_from_utf8("local-name(/root)"), document_);
assert(STRING == result.type());
assert(SA::construct_from_utf8("root") == result.asString());
} // testLocalNameFn1
if (0) {
using namespace Arabica::XPath;
Arabica::DOM::DocumentFragment<std::string> frag = document_.createDocumentFragment();
frag.appendChild(document_.createElement("foo"));
NodeSetVariableResolver svr;
NodeSet<string_type, string_adaptor> ns;
ns.push_back(frag);
svr.setVariable("fruit", ns);
parser.setVariableResolver(svr);
XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("local-name($fruit/foo) == 'foo'"), document_);
std::cout << result.asBool() << std::endl;
}
}