本文整理汇总了C++中poco::xml::Node::innerText方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::innerText方法的具体用法?C++ Node::innerText怎么用?C++ Node::innerText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::xml::Node
的用法示例。
在下文中一共展示了Node::innerText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_text_from_tag
std::string XmlHandler::get_text_from_tag(const std::string &xpath) {
Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode();
Poco::XML::Node *detectorNode = pNode->getNodeByPath(xpath);
std::string value;
if (detectorNode)
value = detectorNode->innerText();
return value;
}
示例2: getFirstElementAtPathInnerText
std::string XMLParserPoco::getFirstElementAtPathInnerText(std::string path)
{
if(_documentLoaded)
{
Poco::XML::Node* node = _document->getNodeByPath(path);
if(node != nullptr)
{
return node->innerText();
}
}
return "";
}
示例3: it
/**
* Build dictionary {string : string } of all tags in the dictionary
* Composed tags: / replaced by _
*
*/
std::map<std::string, std::string>
XmlHandler::get_metadata(const std::string &tag_to_ignore) {
std::map<std::string, std::string> metadata;
Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode();
while (pNode) {
if (pNode->childNodes()->length() == 1 &&
pNode->nodeName() != tag_to_ignore) {
std::string key =
pNode->parentNode()->nodeName() + "/" + pNode->nodeName();
std::string value = pNode->innerText();
metadata.emplace(key, value);
}
pNode = it.nextNode();
}
return metadata;
}
示例4: parseXML
/** Parse XML file and define the following internal variables:
std::vector<detid_t> m_maskDetID;
//spectrum id-s to unmask
std::vector<detid_t> m_unMaskDetID;
spectra mask provided
std::vector<specnum_t> m_maskSpecID;
spectra unmask provided NOT IMPLEMENTED
std::vector<specnum_t> m_unMaskSpecID;
std::vector<std::string> m_maskCompIDSingle;
std::vector<std::string> m_uMaskCompIDSingle;
//
Supported xml Node names are:
component: the name of an instrument component, containing detectors.
ids : spectra numbers
detids : detector numbers
Full implementation needs unit tests verifying all these. Only detector id-s are
currently implemented
// There are also no current support for keyword, switching on un-masking
*/
void LoadMask::parseXML() {
// 0. Check
if (!m_pDoc)
throw std::runtime_error("Call LoadMask::initialize() before parseXML.");
// 1. Parse and create a structure
Poco::AutoPtr<NodeList> pNL_type = m_pRootElem->getElementsByTagName("type");
g_log.information() << "Node Size = " << pNL_type->length() << '\n';
Poco::XML::NodeIterator it(m_pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode();
std::vector<specnum_t> singleSp, pairSp;
std::vector<detid_t> maskSingleDet, maskPairDet;
std::vector<detid_t> umaskSingleDet, umaskPairDet;
bool tomask = true;
bool ingroup = false;
while (pNode) {
const Poco::XML::XMLString value = pNode->innerText();
if (pNode->nodeName() == "group") {
// Node "group"
ingroup = true;
tomask = true;
} else if (pNode->nodeName() == "component") {
// Node "component"
if (ingroup) {
parseComponent(value, tomask, m_maskCompIdSingle, m_uMaskCompIdSingle);
} else {
g_log.error() << "XML File hierarchical (component) error!\n";
}
} else if (pNode->nodeName() == "ids") {
// Node "ids"
if (ingroup) {
parseRangeText(value, singleSp, pairSp);
} else {
g_log.error() << "XML File (ids) hierarchical error!"
<< " Inner Text = " << pNode->innerText() << '\n';
}
} else if (pNode->nodeName() == "detids") {
// Node "detids"
if (ingroup) {
if (tomask) {
parseRangeText(value, maskSingleDet, maskPairDet);
} else { // NOTE -- currently never happens.TODO: NOT IMPLEMENTED
parseRangeText(value, umaskSingleDet, umaskPairDet);
}
} else {
g_log.error() << "XML File (detids) hierarchical error!\n";
}
} else if (pNode->nodeName() == "detector-masking") {
// Node "detector-masking". Check default value
m_defaultToUse = true;
} // END-IF-ELSE: pNode->nodeName()
pNode = it.nextNode();
} // ENDWHILE
convertToVector(singleSp, pairSp, m_maskSpecID);
convertToVector(maskSingleDet, maskPairDet, m_maskDetID);
// NOTE: -- TODO: NOT IMPLEMENTD -- if unmasking is implemented, should be
// enabled
// convertToVector(umaskSingleDet, umaskPairDet, m_unMaskDetID);
}
示例5: parseXML
/*
* Parse XML file
*/
void LoadGroupXMLFile::parseXML() {
// 0. Check
if (!m_pDoc)
throw std::runtime_error(
"Call LoadDetectorsGroupingFile::initialize() before parseXML.");
// 1. Parse and create a structure
Poco::XML::NodeIterator it(m_pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode();
int curgroupid = m_startGroupID - 1;
bool isfirstgroup = true;
// Add flag to figure out it is automatic group ID or user-defined group ID
bool autogroupid = true;
// While loop to go over all nodes!
while (pNode) {
const Poco::XML::XMLString value = pNode->innerText();
if (pNode->nodeName().compare("detector-grouping") == 0) {
// Node "detector-grouping" (first level)
// Optional instrument name
m_instrumentName =
getAttributeValueByName(pNode, "instrument", m_userGiveInstrument);
// Optional date for which is relevant
m_date = getAttributeValueByName(pNode, "idf-date", m_userGiveDate);
// Optional grouping description
m_description =
getAttributeValueByName(pNode, "description", m_userGiveDescription);
} // "detector-grouping"
else if (pNode->nodeName().compare("group") == 0) {
// Group Node: get ID, set map
// a) Find group ID
bool foundid;
std::string idstr = getAttributeValueByName(pNode, "ID", foundid);
if (isfirstgroup && foundid)
autogroupid = false;
else if (!isfirstgroup && !autogroupid && foundid)
autogroupid = false;
else
autogroupid = true;
isfirstgroup = false;
if (autogroupid) {
curgroupid++;
} else {
curgroupid = atoi(idstr.c_str());
}
// b) Set in map
auto itc = m_groupComponentsMap.find(curgroupid);
if (itc != m_groupComponentsMap.end()) {
// Error! Duplicate Group ID defined in XML
std::stringstream ss;
ss << "Map (group ID, components) has group ID " << curgroupid
<< " already. Duplicate Group ID error!" << std::endl;
throw std::invalid_argument(ss.str());
} else {
// When group ID is sorted, check if user has specified a group name
bool foundName;
std::string name = getAttributeValueByName(pNode, "name", foundName);
if (foundName)
m_groupNamesMap[curgroupid] = name;
// Set map
std::vector<std::string> tempcomponents;
std::vector<detid_t> tempdetids;
std::vector<int> tempspectrumids;
m_groupComponentsMap[curgroupid] = tempcomponents;
m_groupDetectorsMap[curgroupid] = tempdetids;
m_groupSpectraMap[curgroupid] = tempspectrumids;
}
} // "group"
else if (pNode->nodeName().compare("component") == 0) {
// Node "component" = value
auto it = m_groupComponentsMap.find(curgroupid);
if (it == m_groupComponentsMap.end()) {
std::stringstream ss;
ss << "XML File (component) heirachial error!"
<< " Inner Text = " << pNode->innerText() << std::endl;
throw std::invalid_argument(ss.str());
} else {
bool valfound;
std::string val_value =
this->getAttributeValueByName(pNode, "val", valfound);
std::string finalvalue;
if (valfound && value.size() > 0)
finalvalue = value + ", " + val_value;
else if (value.size() == 0)
//.........这里部分代码省略.........
示例6: parseXML
/** Parse XML file
*/
void LoadMask::parseXML() {
// 0. Check
if (!m_pDoc)
throw std::runtime_error("Call LoadMask::initialize() before parseXML.");
// 1. Parse and create a structure
Poco::AutoPtr<NodeList> pNL_type = m_pRootElem->getElementsByTagName("type");
g_log.information() << "Node Size = " << pNL_type->length() << std::endl;
Poco::XML::NodeIterator it(m_pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode();
bool tomask = true;
bool ingroup = false;
while (pNode) {
const Poco::XML::XMLString value = pNode->innerText();
if (pNode->nodeName().compare("group") == 0) {
// Node "group"
ingroup = true;
tomask = true;
/*
// get type
Poco::AutoPtr<Poco::XML::NamedNodeMap> att = pNode->attributes();
Poco::XML::Node* cNode = att->item(0);
if (cNode->getNodeValue().compare("mask") == 0 ||
cNode->getNodeValue().compare("notuse") == 0){
tomask = true;
} else if (cNode->getNodeValue().compare("unmask") == 0 ||
cNode->getNodeValue().compare("use") == 0){
tomask = false;
} else {
g_log.error() << "Type (" << cNode->localName() << ") = " <<
cNode->getNodeValue() << " is not supported!" << std::endl;
}
g_log.information() << "Node Group: child Node Name = " <<
cNode->localName() << ": " << cNode->getNodeValue()
<< "(always)"<< std::endl;
*/
} else if (pNode->nodeName().compare("component") == 0) {
// Node "component"
if (ingroup) {
this->parseComponent(value, tomask);
} else {
g_log.error() << "XML File heirachial (component) error!" << std::endl;
}
// g_log.information() << "Component: " << value << std::endl;
} else if (pNode->nodeName().compare("ids") == 0) {
// Node "ids"
if (ingroup) {
this->parseSpectrumNos(value, tomask);
} else {
g_log.error() << "XML File (ids) heirachial error!"
<< " Inner Text = " << pNode->innerText() << std::endl;
}
// g_log.information() << "detids: " << value << std::endl;
} else if (pNode->nodeName().compare("detids") == 0) {
// Node "detids"
if (ingroup) {
this->parseDetectorIDs(value, tomask);
} else {
g_log.error() << "XML File (detids) heirachial error!" << std::endl;
}
} else if (pNode->nodeName().compare("detector-masking") == 0) {
// Node "detector-masking". Check default value
m_defaultToUse = true;
/*
Poco::AutoPtr<Poco::XML::NamedNodeMap> att = pNode->attributes();
if (att->length() > 0){
Poco::XML::Node* cNode = att->item(0);
m_defaultToUse = true;
if (cNode->localName().compare("default") == 0){
if (cNode->getNodeValue().compare("use") == 0){
m_defaultToUse = true;
} else {
m_defaultToUse = false;
}
} // if - att-length
*/
} // END-IF-ELSE: pNode->nodeName()
pNode = it.nextNode();
} // ENDWHILE
return;
}