void gdipp_setting::load_gdimm_process(const xpath_node_set &process_nodes) { // backward iterate so that first-coming process settings overwrites last-coming ones xpath_node_set::const_iterator node_iter = process_nodes.end(); node_iter--; for (size_t i = 0; i < process_nodes.size(); i++, node_iter--) { // only store the setting items which match the current process name const xml_node curr_proc = node_iter->node(); const xml_attribute name_attr = curr_proc.attribute(L"name"); bool process_matched = name_attr.empty(); if (!process_matched) { const wregex name_ex(name_attr.value(), regex_flags); process_matched = regex_match(_process_name, name_ex); } if (process_matched) { for (xml_node::iterator set_iter = node_iter->node().begin(); set_iter != node_iter->node().end(); set_iter++) parse_gdimm_setting_node(*set_iter, _process_setting); } } }
BOOL gdipp_setting::insert_setting(const wchar_t *node_name, const wchar_t *node_text, const wchar_t *parent_xpath, const wchar_t *ref_node_xpath, wstring &new_node_xpath) { // insert the new node as a child node before the reference node, and output its XPath bool b_ret; xml_node parent_node = _xml_doc->select_single_node(parent_xpath).node(); if (parent_node.empty()) return FALSE; const xml_node ref_node = _xml_doc->select_single_node(ref_node_xpath).node(); if (ref_node.empty()) return FALSE; xml_node new_node = parent_node.insert_child_before(node_element, ref_node); if (new_node.empty()) return FALSE; xml_node text_node = new_node.append_child(node_pcdata); if (text_node.empty()) return FALSE; b_ret = new_node.set_name(node_name); if (!b_ret) return FALSE; text_node.set_value(node_text); if (!b_ret) return FALSE; new_node_xpath = new_node.path(); return TRUE; }
string XMLProcessor::returnHashString(xml_node node) { if (node.parent().name() == "") return DBStringProcessor::getOriginalTrueTableName(node.name()); else return returnHashString(node.parent()) + "->" + DBStringProcessor::getOriginalTrueTableName(node.name()); }
void text_symbolizer_properties::text_properties_from_xml(xml_node const& node) { // The options 'margin' and 'repeat-distance' replace 'minimum-distance'. // Only allow one or the other to be defined here. if (node.has_attribute("margin") || node.has_attribute("repeat-distance")) { if (node.has_attribute("minimum-distance")) { throw config_error(std::string("Cannot use deprecated option minimum-distance with " "new options margin and repeat-distance.")); } set_property_from_xml<value_double>(expressions.margin, "margin", node); set_property_from_xml<value_double>(expressions.repeat_distance, "repeat-distance", node); } else { set_property_from_xml<value_double>(expressions.minimum_distance, "minimum-distance", node); } set_property_from_xml<label_placement_e>(expressions.label_placement, "placement", node); set_property_from_xml<value_double>(expressions.label_spacing, "spacing", node); set_property_from_xml<value_double>(expressions.label_position_tolerance, "label-position-tolerance", node); set_property_from_xml<value_double>(expressions.minimum_padding, "minimum-padding", node); set_property_from_xml<value_double>(expressions.minimum_path_length, "minimum-path-length", node); set_property_from_xml<boolean_type>(expressions.avoid_edges, "avoid-edges", node); set_property_from_xml<boolean_type>(expressions.allow_overlap, "allow-overlap", node); set_property_from_xml<boolean_type>(expressions.largest_bbox_only, "largest-bbox-only", node); set_property_from_xml<value_double>(expressions.max_char_angle_delta, "max-char-angle-delta", node); set_property_from_xml<text_upright_e>(expressions.upright, "upright", node); }
void populate_tree(xmlNode *cur_node, xml_node &node) { for (; cur_node; cur_node = cur_node->next ) { switch (cur_node->type) { case XML_ELEMENT_NODE: { xml_node &new_node = node.add_child((const char *)cur_node->name, cur_node->line, false); append_attributes(cur_node->properties, new_node); populate_tree(cur_node->children, new_node); } break; case XML_TEXT_NODE: { std::string trimmed((const char*)cur_node->content); mapnik::util::trim(trimmed); if (trimmed.empty()) break; //Don't add empty text nodes node.add_child(trimmed, cur_node->line, true); } break; case XML_COMMENT_NODE: break; default: break; } } }
void populate_tree(rapidxml::xml_node<char> *cur_node, xml_node &node) { switch (cur_node->type()) { case rapidxml::node_element: { xml_node &new_node = node.add_child((char *)cur_node->name(), 0, false); // Copy attributes for (rapidxml::xml_attribute<char> *attr = cur_node->first_attribute(); attr; attr = attr->next_attribute()) { new_node.add_attribute(attr->name(), attr->value()); } // Copy children for (rapidxml::xml_node<char> *child = cur_node->first_node(); child; child = child->next_sibling()) { populate_tree(child, new_node); } } break; // Data nodes case rapidxml::node_data: case rapidxml::node_cdata: { node.add_child(cur_node->value(), 0, true); } break; default: break; } }
void Editor_Html2Usfm::processNode (xml_node node) { switch (node.type ()) { case node_element: { openElementNode (node); for (xml_node child : node.children()) { processNode (child); } closeElementNode (node); break; } case node_pcdata: { // Add the text to the current USFM line. string text = node.text ().get (); currentLine += text; break; } default: { string nodename = node.name (); Database_Logs::log ("Unknown XML node " + nodename + " while saving editor text"); break; } } }
/** * @brief Configures the block: defines the input file. * @param n The configuration parameters */ virtual void _configure(const xml_node& n) { xml_node source = n.child("source"); xml_node gates_node = n.child("gates"); if( (!source) || (!gates_node) ) throw std::runtime_error("TweetReader: missing parameter"); std::string gates_s = gates_node.attribute("number").value(); std::string type = source.attribute("type").value(); std::string ip = source.attribute("ip").value(); file_name = source.attribute("name").value(); if(!type.length() || !file_name.length() || !gates_s.length()) throw std::runtime_error("TweetReader: missing attribute"); if(type.compare("offline") != 0) throw std::runtime_error("TweetReader: invalid type parameter"); num_gates = atoi(gates_s.c_str()); file.open(file_name); if(!file.is_open()) { throw std::runtime_error("TweetReader: cannot open source file"); } // Create and register the output gates m_outgate_ids = new int[num_gates]; for(int i=0; i<num_gates; i++){ std::string ogate = outgate_basename + boost::lexical_cast<std::string>(i); m_outgate_ids[i] = register_output_gate(ogate.c_str()); } }
node_ptr registry::from_xml(xml_node const& xml, fontset_map const& fontsets) { std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(xml.name()); if (itr == map_.end()) throw config_error("Unknown element '" + xml.name() + "'", xml); xml.set_processed(true); return itr->second(xml, fontsets); }
ProcessResult MsgTypeIqProcessHandler::handler(SessionPtr sessionPtr, const xml_node& node){ ProcessResult result; ostringstream os; sessionPtr->delAllSupportType(); for(xml_node msgType = node.first_child(); msgType; msgType = msgType.next_sibling()){ if(strcmp(msgType.name(), "msgType") != 0){ continue; } string msgTypeStr = msgType.child_value(); boost::trim(msgTypeStr); if(msgTypeStr == "chat"){ sessionPtr->addSupportType(MessageType::CHAT); } else if (msgTypeStr == "feed"){ sessionPtr->addSupportType(MessageType::FEED); } else if (msgTypeStr == "notify"){ sessionPtr->addSupportType(MessageType::NOTIFY); } } string id = node.attribute("id").value(); string from = node.attribute("from").value(); result.setCode(ProcessResult::HAS_RESPONSE); os << "<iq id='" << id << "' to='" << from << "' type='result'>" << "<success/></iq>"; result.setMsg(os.str()); return result; }
WidgetInfo::WidgetInfo(xml_node& nodes, WidgetInfo* parent): _w(nodes),_btree(nodes.attribute("behaviour").as_string()),_parent(parent) { auto i = nodes.children(); for (auto node : nodes) { _nextNode.push_back(new WidgetInfo(node, this)); } }
int Scene::intFromChild(const xml_node &node, const string &child) { xml_node childNode = node.child(child.c_str()); if(!childNode){ stringstream ss; ss << "node <"<< node.name() << "> has no child named '" << child << "'"; throw invalid_argument(ss.str().c_str()); } return childNode.text().as_int(); }
static void get_channelnames (const xml_node &n, std::vector<std::string> &channelnames) { xml_node channel_node = n.child ("channelnames"); for (xml_node n = channel_node.child ("channelname"); n; n = n.next_sibling ("channelname")) { channelnames.push_back (n.child_value ()); } }
string Scene::stringAttributeFromNode(const xml_node &node, const string& attributeName) { xml_attribute attr = node.attribute(attributeName.c_str()); if(!attr){ stringstream ss; ss << "node <"<< node.name() << "> has no '" << attributeName << "' attribute"; throw invalid_argument(ss.str().c_str()); } return attr.as_string(); }
void Camera::parseAlias( xml_node &cur ) { if (isTag(cur.name(), "Alias")) { aliases.push_back(string(cur.first_child().value())); pugi::xml_attribute key = cur.attribute("id"); if (key) canonical_aliases.push_back(string(key.as_string())); else canonical_aliases.push_back(string(cur.first_child().value())); } }
/** * Set an attribute on an XML node. * In theory, XML nodes have an ordered collection of named attributes, duplicates * allowed. In practice, we're using it as an unordered string=>string dictionary. */ template<class T> static void set_attribute(xml_node &node, const char *key, T newValue) { if(node.attribute(key).empty()) { node.append_attribute(key).set_value(newValue); } else { node.attribute(key).set_value(newValue); } }
void AlphaInputBox::loadNode(xml_node node) { TextBox::loadNode(node); if (node.attribute("default") != NULL) { string def = node.attribute("default").as_string(); wstringstream wss; wss << def.c_str(); userInput = wss.str(); } }
bool XMLFPParser::processInputVariable(const xml_node& var_root, MamdaniFuzzyObject* object) { InputLinguisticVariable *variable = new InputLinguisticVariable(var_root.child(LINGUISTIC_VARIABLE_ID_TAG).first_child().value(), parsing::extractFloat(var_root.child(LINGUISTIC_VARIABLE_LOW_BOUND_TAG).child(LINGUISTIC_VARIABLE_VALUE_TAG).first_child().value()), parsing::extractFloat(var_root.child(LINGUISTIC_VARIABLE_UP_BOUND_TAG).child(LINGUISTIC_VARIABLE_VALUE_TAG).first_child().value())); if(!loopFuzzySets(var_root.child(LINGUISTIC_VARIABLE_SETS_TAG),variable)){ LERROR << "Error in parsing the fuzzy set for the variable : " << std::string(var_root.child(LINGUISTIC_VARIABLE_ID_TAG).first_child().value()); return false; } return object->addInputVar(variable); }
result_type operator()(xml_node node) const { if(node.node_type() == Derived::node_type) return true; else if(node.node_type() == node_type::unknown_node && static_cast<Derived const&>(*this).predicate(node)) { node.node_type(Derived::node_type); return true; } else return false; }
/** * configures the filter * @param n the xml subtree */ virtual void _configure(const xml_node& n ) { xml_node config = n.child("config"); xml_node log = n.child("logdir"); if(!config or !log) throw std::runtime_error("TstatAnalyzer: missing parameter"); std::string cname=config.attribute("name").value(); tstat_init((char*)cname.c_str()); std::string lname=config.attribute("name").value(); struct timeval cur_time; gettimeofday(&cur_time,NULL); tstat_new_logdir((char*)lname.c_str(), &cur_time); }
void gdipp_setting::parse_gdimm_setting_node(const xml_node &setting_node, setting_map &setting_store) { const string_t name = setting_node.name(); if (name == L"freetype" || name == L"gamma" || name == L"render_mode" || name == L"shadow") { // these settings have nested items for (xml_node::iterator iter = setting_node.begin(); iter != setting_node.end(); iter++) setting_store[name + L"/" + iter->name()] = iter->first_child().value(); } else setting_store[name] = setting_node.first_child().value(); }
void gdipp_setting::load_demo(const xml_node &root_node) { for (xml_node::iterator iter = root_node.begin(); iter != root_node.end(); iter++) { const wstring node_name = iter->name(); const wstring curr_value = iter->first_child().value(); if (node_name == L"font") _demo_fonts.push_back(curr_value); else _demo_setting[node_name] = curr_value; } }
BOOL gdipp_setting::remove_setting(const wchar_t *node_xpath) { const xml_node node = _xml_doc->select_single_node(node_xpath).node(); if (node.empty()) return FALSE; xml_node parent_node = node.parent(); if (parent_node.empty()) return FALSE; parent_node.remove_child(node); return TRUE; }
void Editor_Html2Usfm::processNoteCitation (xml_node node) { // Remove the note citation from the text. // It means that this: // <a href="#note1" id="citation1" class="superscript">x</a> // becomes this: // <a href="#note1" id="citation1" class="superscript" /> xml_node child = node.first_child (); node.remove_child (child); // Get more information about the footnote to retrieve. string href = node.attribute ("href").value (); string id = href.substr (1); // Sample footnote body. // <p class="x"><a href="#citation1" id="note1">x</a><span> </span><span>+ 2 Joh. 1.1</span></p> // Retrieve the <a> element from it. // At first this was done through an XPath expression: // http://www.grinninglizard.com/tinyxml2docs/index.html // But XPath crashes on Android with libxml2. // Therefore now it iterates of all the nodes to find the required <a> element. // (After moving to pugixml, the XPath expression could have been used again, but this was not done.) xml_node aElement = get_note_pointer (document.first_child (), id); if (aElement) { // It now has the 'a' element: Get its 'p' parent, and then remove that 'a' element. // So we remain with: // <p class="x"><span> </span><span>+ 2 Joh. 1.1</span></p> xml_node pElement = aElement.parent (); pElement.remove_child (aElement); // Preserve active character styles in the main text, and reset them for the note. vector <string> preservedCharacterStyles = characterStyles; characterStyles.clear(); // Process this 'p' element. processingNote = true; processNode (pElement); processingNote = false; // Restore the active character styles for the main text. characterStyles = preservedCharacterStyles; // Remove this element so it can't be processed again. xml_node div_notes = pElement.parent (); div_notes.remove_child (pElement); } else { Database_Logs::log ("Discarding note with id " + id + " and href " + href); } }
void Editor_Html2Usfm::closeElementNode (xml_node node) { // The tag and class names of this element node. string tagName = node.name (); string className = node.attribute ("class").value (); if (tagName == "p") { // While editing it happens that the p element does not have a class. // Use the 'p' class in such cases. if (className == "") className = "p"; if (noteOpeners.find (className) != noteOpeners.end()) { // Deal with note closers. currentLine += usfm_get_closing_usfm (className); } else { // Normally a p element closes the USFM line. flushLine (); mono = false; // Clear active character styles. characterStyles.clear(); } } if (tagName == "span") { // Do nothing for monospace elements, because the USFM would be the text nodes only. if (mono) return; // Do nothing without a class. if (className.empty()) return; // Do nothing if no endmarkers are supposed to be produced. if (suppressEndMarkers.find (className) != suppressEndMarkers.end()) return; // Add closing USFM, optionally closing embedded tags in reverse order. vector <string> classes = filter_string_explode (className, ' '); characterStyles = filter_string_array_diff (characterStyles, classes); reverse (classes.begin(), classes.end()); for (unsigned int offset = 0; offset < classes.size(); offset++) { bool embedded = (classes.size () > 1) && (offset == 0); if (!characterStyles.empty ()) embedded = true; currentLine += usfm_get_closing_usfm (classes [offset], embedded); } } if (tagName == "a") { // Do nothing for note citations in the text. } }
bool XMLFPParser::parseRule (const xml_node& rule, MamdaniFuzzyObject* object){ string rule_string = rule.child(RULE_CONSEQUENT_TAG).child(RULE_VALUE_TAG).first_child().value(); uniformRuleSintax(rule_string); MamdaniRule* toAdd = new MamdaniRule(rule_string); return object->addRule(toAdd); }
vector<Light> Scene::readLights(const xml_node &scene) { xml_node lightsNode = scene.child("lights"); if(!lightsNode) throw domain_error("readLights: Couldn't found <lights> node"); vector<Light> res; for (xml_node node = lightsNode.first_child(); node; node = node.next_sibling()) { if(string(node.name()) != "light") { stringstream ss; ss << "Encountered an invalid <" << node.name() << "> element in the lights element."; throw domain_error(ss.str().c_str()); } Light light( vectorFromChild(node, "position"), colorFromChild(node, "ambientColor"), colorFromChild(node, "diffuseColor"), floatFromChild(node, "linearAttenuation"), floatFromChild(node, "quadAttenuation") ); res.push_back(light); } if(res.empty()){ throw domain_error("No lights found. The scene must have at least one light."); } return res; }
void set_symbolizer_property(Symbolizer & sym, keys key, xml_node const& node) { std::string const& name = std::get<0>(get_meta(key)); if (node.has_attribute(name)) { detail::set_symbolizer_property_impl<Symbolizer,T, std::is_enum<T>::value>::apply(sym,key,name,node); } }
void append_attributes(xmlAttr *attributes, xml_node &node) { for (; attributes; attributes = attributes->next ) { node.add_attribute((const char *)attributes->name, (const char *)attributes->children->content); } }
xml_node ModelToXmlConverter::appendNode(const Node& node, xml_node& xnode) { Logger::entry("info") << "Appending child " << node.name(); xml_node newNode = xnode.append_child(node.name().c_str()); if (node.hasValue()) { newNode.append_child(node_pcdata).set_value(node.value().c_str()); } if (newNode.empty()) { Logger::entry("info") << "Error when adding new xml node " << node.name() << ". Skipping node."; return newNode; } list< Attribute > attributes = node.attributes(); list< Attribute >::iterator attrIt = attributes.begin(); for (; attrIt != attributes.end(); ++attrIt) { xml_attribute attr = newNode.append_attribute(attrIt->name().c_str()); if (attr.empty()) { Logger::entry("info") << "Error when adding new attribute " << attrIt->name() << " to node " << node.name() << ". Skipping attribute."; continue; } attr.set_value(attrIt->value().c_str()); } return newNode; }