本文整理汇总了C++中DOMDocument::createExpression方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::createExpression方法的具体用法?C++ DOMDocument::createExpression怎么用?C++ DOMDocument::createExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createExpression方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
// Initialise Xerces-C and XQilla using XQillaPlatformUtils
XQillaPlatformUtils::initialize();
// Get the XQilla DOMImplementation object
DOMImplementation *xqillaImplementation =
DOMImplementationRegistry::getDOMImplementation(X("XPath2 3.0"));
try {
// Create a DOMLSParser object
AutoRelease<DOMLSParser> parser(xqillaImplementation->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0));
parser->getDomConfig()->setParameter(XMLUni::fgDOMNamespaces, true);
parser->getDomConfig()->setParameter(XMLUni::fgXercesSchema, true);
parser->getDomConfig()->setParameter(XMLUni::fgDOMValidateIfSchema, true);
// Parse a DOMDocument
DOMDocument *document = parser->parseURI("foo.xml");
if(document == 0) {
std::cerr << "Document not found." << std::endl;
return 1;
}
// Parse an XPath 2 expression
AutoRelease<DOMXPathExpression> expression(document->createExpression(X("foo/bar/@baz"), 0));
// Execute the query
AutoRelease<DOMXPathResult> result(expression->evaluate(document, DOMXPathResult::ITERATOR_RESULT_TYPE, 0));
// Create a DOMLSSerializer to output the nodes
AutoRelease<DOMLSSerializer> serializer(xqillaImplementation->createLSSerializer());
AutoRelease<DOMLSOutput> output(xqillaImplementation->createLSOutput());
StdOutFormatTarget target;
output->setByteStream(&target);
// Iterate over the results, printing them
while(result->iterateNext()) {
serializer->write(result->getNodeValue(), output);
std::cout << std::endl;
}
}
catch(XQillaException &e) {
std::cerr << "XQillaException: " << UTF8(e.getString()) << std::endl;
return 1;
}
// Terminate Xerces-C and XQilla using XQillaPlatformUtils
XQillaPlatformUtils::terminate();
return 0;
}
示例2: document
std::vector<std::string> GetXpathResults1(DOMElement* root, std::string querystr)
{
std::vector<std::string> values;
DOMDocument* document (root->getOwnerDocument ());
// Obtain namespace resolver.
xsd::cxx::xml::dom::auto_ptr<XQillaNSResolver> resolver (
(XQillaNSResolver*)document->createNSResolver (root));
//// Create XPath expression.
//xsd::cxx::xml::dom::auto_ptr<const XQillaExpression> expr (
// static_cast<const XQillaExpression*> (
// doc->createExpression (
// xsd::cxx::xml::string (querystr.c_str()).c_str (),
// resolver.get ())));
//
//// Execute the query.
//xsd::cxx::xml::dom::auto_ptr<XPath2Result> r (
// static_cast<XPath2Result*> (
// expr->evaluate (
// doc, XPath2Result::ITERATOR_RESULT, 0)));
// Parse an XPath 2 expression
xsd::cxx::xml::dom::auto_ptr<DOMXPathExpression> expression(
document->createExpression(X (querystr.c_str()), resolver.get ()));
// Execute the query
xsd::cxx::xml::dom::auto_ptr<DOMXPathResult> xQillaResult(
expression->evaluate(
document,
DOMXPathResult::ITERATOR_RESULT_TYPE, 0));
// root, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE /*DOMXPathResult::ITERATOR_RESULT_TYPE*/, 0));
// Not sure it is an ordered list
while (xQillaResult->iterateNext ())
{
//const DOMNode* n (r->asNode ());
//const XMLCh * value = n->getTextContent ( );
char * value = XMLString::transcode(xQillaResult->getStringValue());
values.push_back(value);
delete value;
}
return values;
}
示例3: doc
std::vector<std::string> CXercesUtils::GetXpathResults(DOMElement* root, std::string querystr)
{
std::vector<std::string> values;
DOMDocument* doc (root->getOwnerDocument ());
// Obtain namespace resolver.
xsd::cxx::xml::dom::auto_ptr<DOMXPathNSResolver> resolver (
doc->createNSResolver (root));
// Create XPath expression.
xsd::cxx::xml::dom::auto_ptr<DOMXPathExpression> expr (
doc->createExpression (
xsd::cxx::xml::string (querystr.c_str()).c_str (),
resolver.get ()));
// Execute the query.
xsd::cxx::xml::dom::auto_ptr<DOMXPathResult> r (
expr->evaluate (
root, DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE /*DOMXPathResult::ITERATOR_RESULT_TYPE*/, 0));
// If no query matches, then return empty vector
if (!r.get() )
return values;
// Iterate over the result.
for (int i=0; i < r->getSnapshotLength(); i++)
{
r->snapshotItem(i);
DOMNode* n (r->getNodeValue ());
const XMLCh * value = n->getTextContent ( );
values.push_back(xsd::cxx::xml::transcode<char> (value));
}
return values;
}
示例4: main
//.........这里部分代码省略.........
oBGSAlg.saveCodebookParametersPath(codebook_paramters_path.str());
oBGSAlg.initialize(oCurrInputFrame, R);
// create visualization windows
/*cv::namedWindow("input",cv::WINDOW_AUTOSIZE);
cv::namedWindow("segmentation mask",cv::WINDOW_AUTOSIZE);*/
int xml_roi_counter = 0;
int bgs_roi_counter = 0;
int frame_counter = 0;
//loop through video frames
while(1) {
try {
std::cout << "frame counter = " << frame_counter << std::endl;
oVideoInput >> oCurrInputFrame;
if(oCurrInputFrame.empty())
break;
//Process
oBGSAlg(oCurrInputFrame,oCurrSegmMask);
//oBGSAlg.getBackgroundImage(oCurrReconstrBGImg);
std::vector<F_state_struct> F_states;
// TODO Add function to static lib.
getRegions(oCurrSegmMask, F_states, pminArea);
std::ostringstream object_xpath_expression;
object_xpath_expression << "//object[../@id=\""<< frame_counter++ << "\"]";
cout << currentDateTime() << "object_xpath_expression: " << object_xpath_expression.str() << endl;
const DOMXPathExpression* parsedExpression = document->createExpression(X(object_xpath_expression.str().c_str()), resolver);
DOMXPathResult* iteratorResult = (DOMXPathResult*)parsedExpression->evaluate(document->getDocumentElement(), DOMXPathResult::ITERATOR_RESULT_TYPE, 0);
/*ostringstream xml_rois_path;
xml_rois_path << base_path << "\\" << base_name << "_xml_rois";
cout << "xml_rois_path filename: " << xml_rois_path.str() << endl;
path xml_rois_dir (xml_rois_path.str());
if(!exists(xml_rois_dir)) {
if (create_directories(xml_rois_dir)) {
cout << currentDateTime() << "xml_rois_dir created!" << endl;
} else {
cout << currentDateTime() << "Cannot create xml_rois_dir!" << endl;
return 1;
}
}*/
ostringstream bgs_rois_path;
bgs_rois_path << base_path << "\\" << base_name << "_bgs_rois";
cout << "bgs_rois_path filename: " << bgs_rois_path.str() << endl;
path bgs_rois_dir (bgs_rois_path.str());
if(!exists(bgs_rois_dir)) {
if (create_directories(bgs_rois_dir)) {
cout << currentDateTime() << "bgs_rois_dir created!" << endl;
} else {
cout << currentDateTime() << "Cannot create bgs_rois_dir!" << endl;
return 1;