本文整理汇总了C++中DOMDocument::evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::evaluate方法的具体用法?C++ DOMDocument::evaluate怎么用?C++ DOMDocument::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::evaluate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
bool XmlWorldReader::Read(const std::string &file) {
// ワールドを初期化
try {
initialize();
if (initFlag) {
initializeWorld();
}
} catch (...) {
return false;
}
// TODO: ファイルの有無を確認
// XMLファイルをパース
const XMLCh gLS[] = {chLatin_L, chLatin_S, chNull};
DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser *parser = impl->createLSParser(
DOMImplementationLS::MODE_SYNCHRONOUS, NULL
);
DOMDocument *doc = parser->parseURI(file.c_str());
if (doc == nullptr) {
return false;
}
// rootノードを取得
DOMElement *worldElement = doc->getDocumentElement();
if (worldElement == nullptr) {
parser->release();
return false;
}
{
YPT::XmlString temp("world");
bool res = XMLString::equals(worldElement->getNodeName(), temp);
if (!res) {
parser->release();
return false;
}
}
// ロード用クラス作成
YPT::XmlWorldPartReader partReader(doc);
// XPathコンテキスト作成
DOMXPathNSResolver *resolver = doc->createNSResolver(worldElement);
if (resolver == nullptr) {
parser->release();
return false;
}
YPT::XmlString str, str2;
DOMXPathResult *result;
// --------------------------------------------------
// ワールド全体の設定
// --------------------------------------------------
// ワールド名
str = worldElement->getAttribute(YPT::XmlString("name"));
if (str != "") {
name = str;
}
// 重力ベクトル
result = doc->evaluate(
YPT::XmlString("./gravity"), worldElement, resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL
);
if (result != nullptr) {
if (result->getSnapshotLength() >= 1) {
str = result->getNodeValue()->getTextContent();
b2Vec2 temp;
if (!YPT::ConvertStrToVec2(str.ToChar(), &temp)) {
world.SetGravity(temp);
}
}
result->release();
}
// --------------------------------------------------
// shapes
// --------------------------------------------------
result = doc->evaluate(
YPT::XmlString("./shape"), worldElement, resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL
);
if (result != nullptr) {
const XMLSize_t len = result->getSnapshotLength();
for (XMLSize_t i = 0; i < len; ++i) {
result->snapshotItem(i);
DOMNode *node = result->getNodeValue();
if (node == nullptr) {
continue;
}
DOMNamedNodeMap *nodeMap = node->getAttributes();
if (nodeMap == nullptr) {
continue;
}
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint))
serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint);
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTBOM, gWriteBOM))
serializerConfig->setParameter(XMLUni::fgDOMWRTBOM, gWriteBOM);
//
// Plug in a format target to receive the resultant
// XML stream from the serializer.
//
// StdOutFormatTarget prints the resultant XML stream
// to stdout once it receives any thing from the serializer.
//
XMLFormatTarget *myFormTarget;
if (goutputfile)
myFormTarget=new LocalFileFormatTarget(goutputfile);
else
myFormTarget=new StdOutFormatTarget();
theOutputDesc->setByteStream(myFormTarget);
// get the DOM representation
DOMDocument *doc = parser->getDocument();
//
// do the serialization through DOMLSSerializer::write();
//
if(gXPathExpression!=NULL)
{
XMLCh* xpathStr=XMLString::transcode(gXPathExpression);
DOMElement* root = doc->getDocumentElement();
try
{
DOMXPathNSResolver* resolver=doc->createNSResolver(root);
DOMXPathResult* result=doc->evaluate(
xpathStr,
root,
resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL);
XMLSize_t nLength = result->getSnapshotLength();
for(XMLSize_t i = 0; i < nLength; i++)
{
result->snapshotItem(i);
theSerializer->write(result->getNodeValue(), theOutputDesc);
}
result->release();
resolver->release ();
}
catch(const DOMXPathException& e)
{
XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
<< XERCES_STD_QUALIFIER endl
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
retval = 4;
}
catch(const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
<< XERCES_STD_QUALIFIER endl
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
retval = 4;
}
XMLString::release(&xpathStr);
}