Poco::XML::Node* XMLConfiguration::findElement(int index, Poco::XML::Node* pNode, bool create) { Poco::XML::Node* pRefNode = pNode; if (index > 0) { pNode = pNode->nextSibling(); while (pNode) { if (pNode->nodeName() == pRefNode->nodeName()) { if (--index == 0) break; } pNode = pNode->nextSibling(); } } if (!pNode && create) { if (index == 1) { Poco::AutoPtr<Poco::XML::Element> pElem = pRefNode->ownerDocument()->createElement(pRefNode->nodeName()); pRefNode->parentNode()->appendChild(pElem); return pElem; } else throw Poco::InvalidArgumentException("Element index out of range."); } return pNode; }
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; }
void ofXml::remove(){ Poco::XML::Node * parent = element->parentNode(); if(parent){ parent->removeChild(element); element->release(); element = (Poco::XML::Element*)parent; }else{ clear(); } }
std::string XMLParserPoco::getFirstElementAtPathInnerText(std::string path) { if(_documentLoaded) { Poco::XML::Node* node = _document->getNodeByPath(path); if(node != nullptr) { return node->innerText(); } } return ""; }
void XMLConfiguration::setRaw(const std::string& key, const std::string& value) { std::string::const_iterator it = key.begin(); Poco::XML::Node* pNode = findNode(it, key.end(), _pRoot, true); if (pNode) { unsigned short nodeType = pNode->nodeType(); if (Poco::XML::Node::ATTRIBUTE_NODE == nodeType) { pNode->setNodeValue(value); } else if (Poco::XML::Node::ELEMENT_NODE == nodeType) { Poco::XML::Node* pChildNode = pNode->firstChild(); if (pChildNode) { if (Poco::XML::Node::TEXT_NODE == pChildNode->nodeType()) { pChildNode->setNodeValue(value); } } else { Poco::AutoPtr<Poco::XML::Node> pText = _pDocument->createTextNode(value); pNode->appendChild(pText); } } } else throw NotFoundException("Node not found in XMLConfiguration", key); }
/** * Returns list of sub-nodes for a xpath node * For: xpath = //Data/ * Returns: Detector , DetectorWing */ std::vector<std::string> XmlHandler::get_subnodes(const std::string &xpath) { std::vector<std::string> subnodes; Poco::XML::Node *xpathNode = pDoc->getNodeByPath(xpath); Poco::XML::NodeIterator it(xpathNode, Poco::XML::NodeFilter::SHOW_ELEMENT); Poco::XML::Node *pNode = it.nextNode(); while (pNode) { if (pNode->childNodes()->length() == 1) { subnodes.push_back(pNode->nodeName()); } pNode = it.nextNode(); } return subnodes; }
Poco::XML::Node* XMLConfiguration::findElement(const std::string& name, Poco::XML::Node* pNode, bool create) { Poco::XML::Node* pChild = pNode->firstChild(); while (pChild) { if (pChild->nodeType() == Poco::XML::Node::ELEMENT_NODE && pChild->nodeName() == name) return pChild; pChild = pChild->nextSibling(); } if (create) { Poco::AutoPtr<Poco::XML::Element> pElem = pNode->ownerDocument()->createElement(name); pNode->appendChild(pElem); return pElem; } else return 0; }
bool ofXml::remove(const string& path) // works for both attributes and tags { Poco::XML::Node *node; if(element) { node = element->getNodeByPath(path); } else { ofLogWarning("ofXml") << "remove(): no element set yet"; return false; } if(node) { Poco::XML::Node *n = node->parentNode()->removeChild(node); n->release(); return true; } return false; }
bool ofXml::removeContents() { if(element && element->hasChildNodes()) { Poco::XML::Node* swap; Poco::XML::Node* n = element->firstChild(); while(n->nextSibling() != nullptr) { swap = n->nextSibling(); element->removeChild(n); n = swap; } return true; } return false; }
void Configure::getNetWorkPathAttr(Poco::XML::NamedNodeMap* map, struct NetworkPathInfo* info) { if(map)//看看是否真有属性 { for(int i = 0 ; i < map->length() ; i++)//属性肯定至少0个,用循环一个个取出 { Poco::XML::Node* attr = map->item(i); if(attr->nodeName() == "UserName") { info->username = attr->nodeValue(); } else if(attr->nodeName() == "Password") { info->password = attr->nodeValue(); } }//属性结束 } }
Poco::XML::Node* XMLConfiguration::findElement(const std::string& attr, const std::string& value, Poco::XML::Node* pNode) { Poco::XML::Node* pRefNode = pNode; Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode); if (!(pElem && pElem->getAttribute(attr) == value)) { pNode = pNode->nextSibling(); while (pNode) { if (pNode->nodeName() == pRefNode->nodeName()) { pElem = dynamic_cast<Poco::XML::Element*>(pNode); if (pElem && pElem->getAttribute(attr) == value) break; } pNode = pNode->nextSibling(); } } return pNode; }
/* * Get attribute's value by name from a Node */ std::string LoadGroupXMLFile::getAttributeValueByName(Poco::XML::Node *pNode, std::string attributename, bool &found) { // 1. Init Poco::AutoPtr<Poco::XML::NamedNodeMap> att = pNode->attributes(); found = false; std::string value = ""; // 2. Loop to find for (unsigned long i = 0; i < att->length(); ++i) { Poco::XML::Node *cNode = att->item(i); if (cNode->localName().compare(attributename) == 0) { value = cNode->getNodeValue(); found = true; break; } } // ENDFOR return value; }
void XMLConfiguration::removeRaw(const std::string& key) { Poco::XML::Node* pNode = findNode(key); if (pNode) { if (pNode->nodeType() == Poco::XML::Node::ELEMENT_NODE) { Poco::XML::Node* pParent = pNode->parentNode(); if (pParent) { pParent->removeChild(pNode); } } else if (pNode->nodeType() == Poco::XML::Node::ATTRIBUTE_NODE) { Poco::XML::Attr* pAttr = dynamic_cast<Poco::XML::Attr*>(pNode); Poco::XML::Element* pOwner = pAttr->ownerElement(); if (pOwner) { pOwner->removeAttributeNode(pAttr); } } } }
/** Create the dimension as a MDHistogram dimension. */ Mantid::Geometry::MDHistoDimension* IMDDimensionFactory::doCreate() const { using namespace Mantid::Geometry; if(m_dimensionXML == NULL) { throw std::runtime_error("Must provide dimension xml before creation"); } Poco::XML::NamedNodeMap* attributes = m_dimensionXML->attributes(); //First and only attribute is the dimension id. Poco::XML::Node* dimensionId = attributes->item(0); std::string id = dimensionId->innerText(); std::string name = m_dimensionXML->getChildElement("Name")->innerText(); Poco::XML::Element* unitsElement = m_dimensionXML->getChildElement("Units"); std::string units = "None"; if(NULL != unitsElement) { //Set units if they exist. units = unitsElement->innerText(); } double upperBounds = atof(m_dimensionXML->getChildElement("UpperBounds")->innerText().c_str()); double lowerBounds = atof(m_dimensionXML->getChildElement("LowerBounds")->innerText().c_str()); unsigned int nBins = atoi(m_dimensionXML->getChildElement("NumberOfBins")->innerText().c_str()); Poco::XML::Element* integrationXML = m_dimensionXML->getChildElement("Integrated"); if (NULL != integrationXML) { double upperLimit = atof(integrationXML->getChildElement("UpperLimit")->innerText().c_str()); double lowerLimit = atof(integrationXML->getChildElement("LowerLimit")->innerText().c_str()); //As it is not currently possible to set integration ranges on a MDDimension or MDGeometryDescription, boundaries become integration ranges. upperBounds = upperLimit; lowerBounds = lowerLimit; } return new MDHistoDimension(name, id, units, lowerBounds, upperBounds, nBins); }
string ofXml::getAttribute(const string& path) const { Poco::XML::Node *e; if(element) { if(path.find("[@") == string::npos) { // we need to create a proper path string attributePath = "[@" + path + "]"; e = element->getNodeByPath(attributePath); } else { e = element->getNodeByPath(path); } } else { ofLogWarning("ofXml") << "getAttribute(): no element set yet"; return ""; } if(e) { return e->getNodeValue(); // this will be the value of the attribute } return ""; }
std::map<std::string, std::string> XmlHandler::get_attributes_from_tag(const std::string &xpath) { std::map<std::string, std::string> attributes_map; Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT); Poco::XML::Node *pNode = it.nextNode(); Poco::XML::Node *detectorNode = pNode->getNodeByPath(xpath); if (detectorNode) { Poco::XML::NamedNodeMap *attributes = detectorNode->attributes(); for (unsigned int i = 0; i < attributes->length(); i++) { Poco::XML::Node *attribute = attributes->item(i); attributes_map.emplace(attribute->nodeName(), attribute->nodeValue()); } } return attributes_map; }
void Configure::loadChannelList(void) { std::ifstream in(SystemInfo::instance().getExecutePath() + "\\config\\channelList.xml"); Poco::XML::InputSource src(in); Poco::XML::DOMParser parser; try { Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src); Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL); Poco::XML::Node* pNode = it.nextNode(); static int index = 0; std::string channelInfo[3]; while (pNode) { if(pNode->nodeName() == "Row") { pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } index = 0; if(m_encodeChannel == channelInfo[1]) { // 找到频道对照表 m_encodeChannelID = channelInfo[0]; m_encodeChannelPrefix = channelInfo[2]; LOG(INFO) << "get channel info : ID [" << m_encodeChannelID << "] Prefix[" << m_encodeChannelPrefix << "]."; return; } } if(pNode->nodeName() == "Cell") { pNode = it.nextNode(); if(pNode->nodeName() != "#text") { pNode = it.nextNode(); continue; //No text node present } channelInfo[index++] = pNode->nodeValue(); } pNode = it.nextNode();//指向下一个node } } catch(std::exception& e) { LOG(ERROR) << "parse channelList xml file error." << e.what() ; } }
void Configure::getOutputStreamAttr(Poco::XML::NamedNodeMap* map, struct OutputStream* outputstream) { if(map)//看看是否真有属性 { for(int i = 0 ; i < map->length() ; i++)//属性肯定至少0个,用循环一个个取出 { Poco::XML::Node* attr = map->item(i); if(attr->nodeName() == "Enable") { outputstream->enable = attr->nodeValue(); } else if(attr->nodeName() == "BitRate") { outputstream->bitrate = attr->nodeValue(); } else if(attr->nodeName() == "ResolutionRatio") { outputstream->resolutionRatio = attr->nodeValue(); } }//属性结束 } }
/** * 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; }
svgtiny_code svgtiny_parse_text(Poco::XML::Element *text, struct svgtiny_parse_state state) { float x, y, width, height; float px, py; Poco::XML::Element *child; svgtiny_parse_position_attributes(text, state, &x, &y, &width, &height); svgtiny_parse_font_attributes(text, &state); svgtiny_parse_transform_attributes(text, &state); px = state.ctm.a * x + state.ctm.c * y + state.ctm.e; py = state.ctm.b * x + state.ctm.d * y + state.ctm.f; /* state.ctm.e = px - state.origin_x; */ /* state.ctm.f = py - state.origin_y; */ /*struct css_style style = state.style; style.font_size.value.length.value *= state.ctm.a;*/ //for (child = text->children; child; child = child->next) { //for( child = (Poco::XML::Element*) text->FirstChild( false ); child; child = (Poco::XML::Element*) child->NextSibling( false ) ) { Poco::XML::NodeIterator it(text, Poco::XML::NodeFilter::SHOW_ELEMENT | Poco::XML::NodeFilter::SHOW_TEXT); Poco::XML::Node* pNode = it.nextNode(); while (pNode) { svgtiny_code code = svgtiny_OK; if (pNode->getNodeValue().compare("text") == 0) { struct svgtiny_shape *shape = svgtiny_add_shape(&state); if (!shape) return svgtiny_OUT_OF_MEMORY; //shape->text = strdup((const char *) child->content); shape->text = strdup((const char *) pNode->getNodeValue().c_str()); shape->text_x = px; shape->text_y = py; state.diagram->shape_count++; } //else if (strcmp((const char *) child->Value(), "tspan") == 0) else if (pNode->getNodeValue().compare("tspan") == 0) { code = svgtiny_parse_text(child, state); } pNode = it.nextNode(); if (code == svgtiny_OK) return code; } return svgtiny_OK; }
/** * Parse the runinfo file to find the names of the neutron event files. * * @param runinfo Runinfo file with full path. * @param dataDir Directory where the runinfo file lives. * @param eventFilenames vector of all possible event files. This is filled by the algorithm. */ void LoadPreNexus::parseRuninfo(const string &runinfo, string &dataDir, vector<string> &eventFilenames) { eventFilenames.clear(); // Create a Poco Path object for runinfo filename Poco::Path runinfoPath(runinfo, Poco::Path::PATH_GUESS); // Now lets get the directory Poco::Path dirPath(runinfoPath.parent()); dataDir = dirPath.absolute().toString(); g_log.debug() << "Data directory \"" << dataDir << "\"\n"; std::ifstream in(runinfo.c_str()); Poco::XML::InputSource src(in); Poco::XML::DOMParser parser; Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src); Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT); Poco::XML::Node* pNode = it.nextNode(); // root node while (pNode) { if (pNode->nodeName() == "RunInfo") // standard name for this type { pNode = pNode->firstChild(); while (pNode) { if (pNode->nodeName() == "FileList") { pNode = pNode->firstChild(); while (pNode) { if (pNode->nodeName() == "DataList") { pNode = pNode->firstChild(); while (pNode) { if (pNode->nodeName() == "scattering") { Poco::XML::Element* element = static_cast<Poco::XML::Element*> (pNode); eventFilenames.push_back(element->getAttribute("name")); } pNode = pNode->nextSibling(); } } else // search for DataList pNode = pNode->nextSibling(); } } else // search for FileList pNode = pNode->nextSibling(); } } else // search for RunInfo pNode = pNode->nextSibling(); } // report the results to the log if (eventFilenames.size() == 1) { g_log.debug() << "Found 1 event file: \"" << eventFilenames[0] << "\"\n"; } else { g_log.debug() << "Found " << eventFilenames.size() << " event files:"; for (size_t i = 0; i < eventFilenames.size(); i++) { g_log.debug() << "\"" << eventFilenames[i] << "\" "; } g_log.debug() << "\n"; } }
Expression::Pointer StandardElementHandler::Create(ExpressionConverter* converter, Poco::XML::Element* element) { std::string name= element->nodeName(); if (ExpressionTagNames::INSTANCEOF == name) { Expression::Pointer result(new InstanceofExpression(element)); return result; } else if (ExpressionTagNames::TEST == name) { Expression::Pointer result(new TestExpression(element)); return result; } else if (ExpressionTagNames::OR == name) { CompositeExpression::Pointer result(new OrExpression()); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::AND == name) { CompositeExpression::Pointer result(new AndExpression()); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::NOT == name) { Poco::XML::Node* child = element->firstChild(); while (child != 0) { if (child->nodeType() == Poco::XML::Node::ELEMENT_NODE) { Expression::Pointer result(new NotExpression(converter->Perform(static_cast<Poco::XML::Element*>(child)))); return result; } child = child->nextSibling(); } } else if (ExpressionTagNames::WITH == name) { CompositeExpression::Pointer result(new WithExpression(element)); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::ADAPT == name) { CompositeExpression::Pointer result(new AdaptExpression(element)); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::ITERATE == name) { CompositeExpression::Pointer result(new IterateExpression(element)); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::COUNT == name) { Expression::Pointer result(new CountExpression(element)); return result; } else if (ExpressionTagNames::SYSTEM_TEST == name) { Expression::Pointer result(new SystemTestExpression(element)); return result; } else if (ExpressionTagNames::RESOLVE == name) { CompositeExpression::Pointer result(new ResolveExpression(element)); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::ENABLEMENT == name) { CompositeExpression::Pointer result(new EnablementExpression(element)); this->ProcessChildren(converter, element, result); return result; } else if (ExpressionTagNames::EQUALS == name) { Expression::Pointer result(new EqualsExpression(element)); return result; } else if (ExpressionTagNames::REFERENCE == name) { Expression::Pointer result(new ReferenceExpression(element)); return result; } return Expression::Pointer(); }
/** 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; }
/** 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); }
bool Configure::load(void) { std::ifstream in(SystemInfo::instance().getExecutePath() + "\\config\\sys.xml"); Poco::XML::InputSource src(in); Poco::XML::DOMParser parser; try { Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src); Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL); Poco::XML::Node* pNode = it.nextNode(); while (pNode) { if(pNode->nodeName() == "EncodChannel") { pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } m_encodeChannel = pNode->nodeValue(); Poco::XML::XMLString tt = Poco::XML::toXMLString(m_encodeChannel); } if(pNode->nodeName() == "InputTSPath") { getNetWorkPathAttr(pNode->attributes(),&m_inputTSPath); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } m_inputTSPath.path = pNode->nodeValue(); m_inputTSPath.objectName = "o:"; } if(pNode->nodeName() == "InputXMLPath") { getNetWorkPathAttr(pNode->attributes(),&m_inputXMLPath); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } m_inputXMLPath.path = pNode->nodeValue(); m_inputXMLPath.objectName = "p:"; } if(pNode->nodeName() == "OutputTSPath") { getNetWorkPathAttr(pNode->attributes(),&m_outputTSPath); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } m_outputTSPath.path = pNode->nodeValue(); m_outputTSPath.objectName = "q:"; } if(pNode->nodeName() == "OutputXMLPath") { getNetWorkPathAttr(pNode->attributes(),&m_outputXMLPath); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } m_outputXMLPath.path = pNode->nodeValue(); m_outputXMLPath.objectName = "r:"; } if(pNode->nodeName() == "OutputStream1") { getOutputStreamAttr(pNode->attributes(),&m_outputStream[0]); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } } if(pNode->nodeName() == "OutputStream2") { getOutputStreamAttr(pNode->attributes(),&m_outputStream[1]); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } } if(pNode->nodeName() == "OutputStream3") { getOutputStreamAttr(pNode->attributes(),&m_outputStream[2]); pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } } if(pNode->nodeName() == "Storage") { if(pNode->attributes())//看看是否真有属性 { for(int i = 0 ; i < pNode->attributes()->length() ; i++) { Poco::XML::Node* attr = pNode->attributes()->item(i); if(attr->nodeName() == "KeepingDateTime") { m_keepDateTime = boost::lexical_cast<int>(attr->nodeValue()); } }//属性结束 } pNode = it.nextNode(); if(pNode->nodeName() != "#text") { continue; //No text node present } } //LOG(INFO) << "name : " << pNode->nodeName() ;//取出当前节点的Name //LOG(INFO)<< "value : " << pNode->nodeValue() ;//取出当前节点的Value pNode = it.nextNode();//指向下一个node } } catch(std::exception& e) { LOG(ERROR) << "parse xml file error." << e.what() ; return false; } this->loadChannelList(); if(m_encodeChannel.empty() || m_encodeChannelID.empty() || m_encodeChannelPrefix.empty() || m_inputTSPath.path.empty() || m_inputTSPath.objectName.empty() || m_inputXMLPath.path.empty() || m_inputXMLPath.objectName.empty() || m_outputTSPath.path.empty() || m_outputTSPath.objectName.empty() || m_outputXMLPath.path.empty() || m_outputXMLPath.objectName.empty() || m_outputStream[0].bitrate.empty() || m_outputStream[0].enable.empty() || m_outputStream[0].resolutionRatio.empty() || m_outputStream[1].bitrate.empty() || m_outputStream[1].enable.empty() || m_outputStream[1].resolutionRatio.empty() || m_outputStream[2].bitrate.empty() || m_outputStream[2].enable.empty() || m_outputStream[2].resolutionRatio.empty() || m_keepDateTime == -2) { return false; } LOG(INFO) << "EncodChannel [" << Configure::instance().m_encodeChannel << "] ID[" << m_encodeChannelID << "] Prefix[" << m_encodeChannelPrefix << "]."; LOG(INFO) << "InputTSPath [" << Configure::instance().m_inputTSPath.path << "]" << " as [" << Configure::instance().m_inputTSPath.objectName << "]"; LOG(INFO) << "InputXMLPath [" << Configure::instance().m_inputXMLPath.path << "]" << " as [" << Configure::instance().m_inputXMLPath.objectName << "]"; LOG(INFO) << "OutputTSPath [" << Configure::instance().m_outputTSPath.path << "]" << " as [" << Configure::instance().m_outputTSPath.objectName << "]"; LOG(INFO) << "OutputXMLPath [" << Configure::instance().m_outputXMLPath.path << "]" << " as [" << Configure::instance().m_outputXMLPath.objectName << "]"; LOG(INFO) << "OutputStream1 [" << Configure::instance().m_outputStream[0].enable << ", " << Configure::instance().m_outputStream[0].bitrate << ", " << Configure::instance().m_outputStream[0].resolutionRatio << "]"; LOG(INFO) << "OutputStream2 [" << Configure::instance().m_outputStream[1].enable << ", " << Configure::instance().m_outputStream[1].bitrate << ", " << Configure::instance().m_outputStream[1].resolutionRatio << "]"; LOG(INFO) << "OutputStream3 [" << Configure::instance().m_outputStream[2].enable << ", " << Configure::instance().m_outputStream[2].bitrate << ", " << Configure::instance().m_outputStream[2].resolutionRatio << "]"; LOG(INFO) << "stoage keep DateTime [" << m_keepDateTime << "]."; return true; }
/* * 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) finalvalue = val_value; else finalvalue = value; it->second.push_back(finalvalue); } } // Component else if (pNode->nodeName().compare("detids") == 0) { // Node "detids" auto it = m_groupDetectorsMap.find(curgroupid); if (it == m_groupDetectorsMap.end()) { std::stringstream ss; ss << "XML File (detids) hierarchal 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) finalvalue = val_value; else finalvalue = value; std::vector<int> parsedRange = Strings::parseRange(finalvalue); it->second.insert(it->second.end(), parsedRange.begin(), parsedRange.end()); } } // "detids" else if (pNode->nodeName().compare("ids") == 0) { // Node ids: for spectrum number auto it = m_groupSpectraMap.find(curgroupid); if (it == m_groupSpectraMap.end()) { std::stringstream ss; ss << "XML File (ids) hierarchal 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) finalvalue = val_value; else finalvalue = value; std::vector<int> parsedRange = Strings::parseRange(finalvalue); it->second.insert(it->second.end(), parsedRange.begin(), parsedRange.end()); } } // Next Node! pNode = it.nextNode(); } // ENDWHILE return; }