本文整理汇总了C++中arabica::xpath::XPath类的典型用法代码示例。如果您正苦于以下问题:C++ XPath类的具体用法?C++ XPath怎么用?C++ XPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XPath类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: is
NistXmlTestset::NistXmlTestset(const std::string &file)
: logger_(logkw::channel = "NistXmlTestset") {
Arabica::SAX2DOM::Parser<std::string> domParser;
Arabica::SAX::InputSource<std::string> is(file);
Arabica::SAX::CatchErrorHandler<std::string> errh;
domParser.setErrorHandler(errh);
domParser.parse(is);
if(errh.errorsReported())
BOOST_LOG_SEV(logger_, error) << errh.errors();
Arabica::DOM::Document<std::string> doc = domParser.getDocument();
if(doc == 0) {
BOOST_LOG_SEV(logger_, error) << "Error parsing input file: " << file;
exit(1);
}
doc.getDocumentElement().normalize();
Arabica::XPath::XPath<std::string> xp;
Arabica::XPath::NodeSet<std::string> docnodes =
xp.compile("/mteval/srcset/doc").evaluateAsNodeSet(doc.getDocumentElement());
docnodes.to_document_order();
BOOST_FOREACH(Arabica::DOM::Node<std::string> n, docnodes)
documents_.push_back(boost::make_shared<NistXmlDocument>(n));
outdoc_ = static_cast<Arabica::DOM::Document<std::string> >(doc.cloneNode(true));
Arabica::DOM::Element<std::string> srcset =
static_cast<Arabica::DOM::Element<std::string> >(
xp.compile("/mteval/srcset").evaluateAsNodeSet(outdoc_.getDocumentElement())[0]);
Arabica::DOM::Element<std::string> tstset = outdoc_.createElement("tstset");
int docno = 0;
while(srcset.hasChildNodes()) {
Arabica::DOM::Node<std::string> n = srcset.removeChild(srcset.getFirstChild());
tstset.appendChild(n);
if(n.getNodeType() == Arabica::DOM::Node<std::string>::ELEMENT_NODE &&
n.getNodeName() == "doc")
documents_[docno++]->setOutputNode(n);
}
tstset.setAttribute("setid", srcset.getAttribute("setid"));
tstset.setAttribute("srclang", srcset.getAttribute("srclang"));
tstset.setAttribute("trglang", "TRGLANG");
tstset.setAttribute("sysid", "SYSID");
srcset.getParentNode().replaceChild(tstset, srcset);
}
开发者ID:mtfelix,项目名称:docent,代码行数:47,代码来源:NistXmlTestset.cpp
示例2: main
int main(int argc, char** argv) {
factory_ = Arabica::SimpleDOM::DOMImplementation<string_type, string_adaptor>::getDOMImplementation();
document_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
root_ = document_.createElement("root");
document_.appendChild(root_);
assert(root_);
element1_ = document_.createElement(SA::construct_from_utf8("child1"));
element2_ = document_.createElement(SA::construct_from_utf8("child2"));
element3_ = document_.createElement(SA::construct_from_utf8("child3"));
element1_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1"));
element2_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1"));
element2_.setAttribute(SA::construct_from_utf8("two"), SA::construct_from_utf8("1"));
element2_.setAttribute(SA::construct_from_utf8("three"), SA::construct_from_utf8("1"));
element2_.setAttribute(SA::construct_from_utf8("four"), SA::construct_from_utf8("1"));
text_ = document_.createTextNode(SA::construct_from_utf8("data"));
comment_ = document_.createComment(SA::construct_from_utf8("comment"));
processingInstruction_ = document_.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data"));
element2_.appendChild(text_);
spinkle_ = document_.createElement(SA::construct_from_utf8("spinkle"));
element2_.appendChild(spinkle_);
element2_.appendChild(comment_);
element2_.appendChild(processingInstruction_);
attr_ = element1_.getAttributeNode(SA::construct_from_utf8("one"));
root_.appendChild(element1_);
root_.appendChild(element2_);
root_.appendChild(element3_);
chapters_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0);
chapters_.appendChild(chapters_.createElement(SA::construct_from_utf8("document")));
chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("one")));
chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("two")));
chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("three")));
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) {
//.........这里部分代码省略.........
开发者ID:juehv,项目名称:uscxml,代码行数:101,代码来源:test-arabica-xpath.cpp
示例3:
Copy_base()
{
Arabica::XPath::XPath<std::string> compiler;
namespace_select_ = compiler.compile("namespace::node()");
} // Copy_base
开发者ID:KITSVictorGubin,项目名称:jornal,代码行数:5,代码来源:xslt_copy.hpp
示例4: assertEquals
void testFollowing1()
{
XPathValue_t nodes = parser_.evaluate(SA::construct_from_utf8("/root/text()/following::node()"), document_);
assertEquals(0, nodes.asNodeSet().size());
} // testFollowing1
开发者ID:QuentinFiard,项目名称:arabica,代码行数:5,代码来源:text_node_test.hpp
示例5: testDescendant
void testDescendant()
{
XPathValue_t nodes = parser_.evaluate(SA::construct_from_utf8("/descendant::text()"), document_);
assertEquals(1, nodes.asNodeSet().size());
} // testDescendant
开发者ID:QuentinFiard,项目名称:arabica,代码行数:5,代码来源:text_node_test.hpp
示例6: testNodeTest
void testNodeTest()
{
XPathValue_t nodes = parser_.evaluate(SA::construct_from_utf8("/root/node()"), document_);
assertEquals(1, nodes.asNodeSet().size());
} // testNodeTest
开发者ID:QuentinFiard,项目名称:arabica,代码行数:5,代码来源:text_node_test.hpp
示例7: extraSetUp
void testTextValue4()
{
extraSetUp();
string_type value = parser_.evaluate(SA::construct_from_utf8("/root/text()[2]"), document_).asString();
assertTrue(SA::construct_from_utf8("fourfive") == value);
} // testTextValue4
开发者ID:QuentinFiard,项目名称:arabica,代码行数:6,代码来源:text_node_test.hpp
示例8: assertTrue
void testTextValue3()
{
string_type value = parser_.evaluate(SA::construct_from_utf8("/root/text()[1]"), document_).asString();
assertTrue(SA::construct_from_utf8("onetwothree") == value);
} // testTextValue3
开发者ID:QuentinFiard,项目名称:arabica,代码行数:5,代码来源:text_node_test.hpp
注:本文中的arabica::xpath::XPath类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论