本文整理汇总了C++中xml_node::select_nodes方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_node::select_nodes方法的具体用法?C++ xml_node::select_nodes怎么用?C++ xml_node::select_nodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml_node
的用法示例。
在下文中一共展示了xml_node::select_nodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: idoc_create_direct
/// @brief Creates an IDoc file based on an XML template and returns it as a string
/// @param a string containing the IDoc's XML template
/// @return a string containing a new flat-text IDoc
IDOCREPLAYDLL_API LPCSTR idoc_create_direct(const LPCSTR idocXml)
{
if (idocXml == NULL)
{
lr_error_message("[%s] IDoc XML cannot be NULL.", __FUNCTION__);
return FALSE;
}
if (!ensure_valid_license())
{
return NULL;
}
const LPCSTR idocXmlPartiallyProcessed = idoc_eval_string(idocXml);
const char* idocXmlProcessed = lr_eval_string(idocXmlPartiallyProcessed);
const char* idocXmlFinal = idocXmlProcessed == NULL ? idocXmlPartiallyProcessed : idocXmlProcessed;
xml_document doc;
doc.load(idocXmlFinal);
if (doc.empty())
{
lr_error_message("[%s] The specified IDoc XML document is empty.", __FUNCTION__);
return NULL;
}
const xpath_node_set segmentNodeSet = doc.root().select_nodes("//IDOC/*[@SEGMENT='1']");
if (segmentNodeSet.empty())
{
lr_error_message("[%s] The specified IDoc XML is not a valid IDoc.", __FUNCTION__);
return NULL;
}
stringstream resultStream;
for (xpath_node_set::const_iterator segmentIterator = segmentNodeSet.begin();
segmentIterator != segmentNodeSet.end();
++segmentIterator)
{
const xml_node segmentNode = segmentIterator->node();
const xpath_node_set fieldNodeSet = segmentNode.select_nodes("./*");
if (fieldNodeSet.empty())
{
lr_error_message(
"[%s] The specified IDoc XML contains segment '%s' without fields.",
__FUNCTION__,
segmentNode.name());
return NULL;
}
for (xpath_node_set::const_iterator fieldIterator = fieldNodeSet.begin();
fieldIterator != fieldNodeSet.end();
++fieldIterator)
{
static const unsigned int InvalidLength = 0xFFFFFFFF;
const xml_node fieldNode = fieldIterator->node();
const unsigned int length = fieldNode.attribute("length").as_uint(InvalidLength);
if (length == InvalidLength)
{
lr_error_message(
"[%s]: The specified IDoc XML contains field '%s:%s' without length or with invalid one.",
__FUNCTION__,
segmentNode.name(),
fieldNode.name());
return NULL;
}
string fieldText(fieldNode.text().as_string());
if (fieldText.length() > length)
{
lr_error_message(
"[%s] The specified IDoc XML contains field '%s:%s' which actual length (%u) is greater"
" than declared (%u).",
__FUNCTION__,
segmentNode.name(),
fieldNode.name(),
fieldText.length(),
length);
return NULL;
}
const size_t padCount = length - fieldText.length();
if (padCount > 0)
{
fieldText.append(padCount, ' ');
}
resultStream << fieldText;
}
resultStream << endl;
}
g_allocatedStrings.push_back(resultStream.str());
const string& resultingDocument = g_allocatedStrings.back();
return resultingDocument.c_str();
//.........这里部分代码省略.........