void iterate_and_get_elements(xmlNode * a_node) { xmlNode *cur_node = NULL; xmlAttr *attribute; xmlChar *text; double minLatitude = 200; double maxLatitude = -200; double minLongitude = 200; double maxLongitude = -200; double latitude; double longitude; for(cur_node = a_node->children; cur_node; cur_node = cur_node->next){ if(cur_node->type == XML_ELEMENT_NODE) { attribute = cur_node->properties; if(verbose) printf("node type: Element, name: %s\n", cur_node->name); if (xmlHasProp(cur_node, "lat") == NULL) continue; text = xmlGetProp(cur_node,"lat"); latitude = atof(text); if(verbose) printf(" latitude: %s\n", text); if (xmlHasProp(cur_node, "lon") == NULL) continue; text = xmlGetProp(cur_node,"lon"); longitude = atof(text); if(verbose) printf(" longitude: %s\n", text); if(latitude > maxLatitude) maxLatitude = latitude; if(latitude < minLatitude) minLatitude = latitude; if(longitude < minLongitude) minLongitude = longitude; if(longitude > maxLongitude) maxLongitude = longitude; } } if(verbose){ printf("The maximum latitude is: %8.8f\n",maxLatitude); printf("The minimum latitude is: %8.8f\n",minLatitude); printf("The maximum longitude is: %8.8f\n",maxLongitude); printf("The minimum longitude is: %8.8f\n",minLongitude); } printf("("); printf("%8.7f,",minLatitude-addTo); printf("%8.7f,",minLongitude-addTo); printf("%8.7f,",maxLatitude+addTo); printf("%8.7f",maxLongitude+addTo); printf(")\n"); }
char *getIDs (xmlNodePtr parentTag) { char *retVal = NULL; xmlNodePtr curNode; xmlChar *tmpStr; if (parentTag->children) curNode=parentTag->children; else return (NULL); while (curNode) { if (curNode->type == XML_ELEMENT_NODE) { if (strcasecmp ((char*)curNode->name, "id") == 0) { if (xmlHasProp(curNode, (xmlChar*)"moviedb")) { tmpStr = xmlGetProp(curNode, (xmlChar*)"moviedb"); if (strcasecmp((char*)tmpStr, "imdb") == 0) { xmlFree (tmpStr); tmpStr = xmlNodeGetContent(curNode); retVal = strdup ((char*)tmpStr); xmlFree (tmpStr); return (retVal); } else xmlFree (tmpStr); } } } curNode=curNode->next; } return (NULL); }
bool ParticleParser::put(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur) { if(xmlHasProp(cur, (const xmlChar *) "file")) { const char* fname =(const char*)(xmlGetProp(cur, (const xmlChar *) "file")); string pformat = getExtension(fname); if(pformat == "xml") { XMLParticleParser aHandle(ref_); return aHandle.put(fname); } else { WARNMSG("Using old formats") ifstream fin(fname); if(fin) { ParticleInputFactory::createParticle(ref_,fin); } else { ERRORMSG("File " << fname << "is not found."); } return true; } } XMLParticleParser aHandle(ref_); aHandle.put(doc,ns,cur); return false; }
/** * Returns the attribute with the specified name in no namespace, or null if * this element does not have an attribute with that name in no namespace. * @param name the name of the attribute . * @return the attribute of this element with the specified name. */ Attribute *Element::getAttribute(String name) { xmlAttr *attr = xmlHasProp(NODE(node), name); if(!attr) return 0; else return static_cast<Attribute *>(get(attr)); }
xmlNodePtr empathy_xml_node_find_child_prop_value (xmlNodePtr node, const gchar *prop_name, const gchar *prop_value) { xmlNodePtr l; xmlNodePtr found = NULL; g_return_val_if_fail (node != NULL, NULL); g_return_val_if_fail (prop_name != NULL, NULL); g_return_val_if_fail (prop_value != NULL, NULL); for (l = node->children; l && !found; l = l->next) { xmlChar *prop; if (!xmlHasProp (l, (const xmlChar *) prop_name)) continue; prop = xmlGetProp (l, (const xmlChar *) prop_name); if (prop && strcmp ((const gchar *) prop, prop_value) == 0) found = l; xmlFree (prop); } return found; }
static HRESULT WINAPI xmlelem_removeAttribute(IXMLElement *iface, BSTR strPropertyName) { xmlelem *This = impl_from_IXMLElement(iface); xmlChar *name; xmlAttrPtr attr; int res; HRESULT hr = S_FALSE; TRACE("(%p, %s)\n", iface, debugstr_w(strPropertyName)); if (!strPropertyName) return E_INVALIDARG; name = xmlChar_from_wchar(strPropertyName); attr = xmlHasProp(This->node, name); if (!attr) goto done; res = xmlRemoveProp(attr); if (res == 0) hr = S_OK; done: HeapFree(GetProcessHeap(), 0, name); return hr; }
void osync_xml_node_remove_unknown_mark(xmlNode *node) { xmlAttr *attr = xmlHasProp(node, (xmlChar*)"Type"); if (!attr) return; xmlRemoveProp(attr); }
xmlNode* RheiaConfigurationManager::AddRootChildren( const wxString& path, const wxString& property, const wxString& propertyValue ) { xmlNode *ret; xmlNode* child = m_root->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char*) child->name ); if ( ChildName.IsSameAs( path ) ) { xmlAttr *prop = xmlHasProp( child , rxU2C( property ) ); if ( prop ) { wxString propVal = RheiaXmlManager::RheiaNodeGetContent( prop->children ); if ( propVal.IsSameAs( propertyValue) ) return child; } } child = child->next; } ret = xmlNewNode( NULL , rxU2C( path ) ); xmlNewProp( ret , rxU2C( property ), rxU2C( propertyValue ) ); ret = xmlAddChild( m_root , ret ); return ret; }
int CXML::GetAttrPtr(const char *a_chPath, const char *a_chAttrName, int nIndex, xmlAttrPtr *a_stAttrPtr) { int nRet = XML_OK; int i = 0; xmlAttrPtr pAttr = NULL; xmlAttrPtr pFindAttr = NULL; xmlNodePtr pNode = NULL; nRet = GetNodeFromXPath(a_chPath, &pNode); if(nRet != XML_OK){ XML_LOG(XML_ERR,"Node not exist(ret=%d, path=%s, attrName=%s)\n",nRet, a_chPath, a_chAttrName); return nRet; } pAttr = xmlHasProp(pNode, (const xmlChar*)a_chAttrName); if(nIndex < 1){ nIndex = 1; } for(i=1;(pAttr != NULL);pAttr=pAttr->next){ if(strcasecmp((const char*)pAttr->name,a_chAttrName) == 0){ if(nIndex == i){ *a_stAttrPtr = pAttr; return XML_OK; } else { i++; } } } XML_LOG(XML_ERR,"Attribute not exit(path=%s, attrName=%s, index=%d)\n",a_chPath, a_chPath, nIndex); return XML_ATTR_NOT_EXIT; }
void ThreadedBlock::postInvoke(Context *ctx, InvokeContext *invoke_ctx) { Block::postInvoke(ctx, invoke_ctx); if (invoke_ctx->error()) { return; } bool show_elapsed_time = trb_data_->check_elapsed_time_ ? trb_data_->check_elapsed_time_ : OperationMode::instance()->checkDevelopmentVariable(ctx->request(), ThreadedBlockData::SHOW_ELAPSED_TIME); if (!show_elapsed_time || tagged()) { return; } xmlNodePtr node = xmlDocGetRootElement(invoke_ctx->resultDoc().get()); if (NULL == node) { return; } const xmlChar* elapsed_attr = (const xmlChar*)"elapsed-time"; std::string elapsed = boost::lexical_cast<std::string>(0.001*ctx->timer().elapsed()); if (xmlHasProp(node, elapsed_attr) && xmlUnsetProp(node, elapsed_attr) < 0) { log()->error("Cannot unset elapsed-time attribute"); return; } xmlNewProp(node, elapsed_attr, (const xmlChar*)elapsed.c_str()); }
void rss_parse_document(RSS* rss, xmlDocPtr doc) { xmlNodePtr node; // Get the root node if (!rss->errno && (node = xmlDocGetRootElement(doc)) == NULL) rss->errno = RSS_E_UNABLE_TO_PARSE; // Make sure it's an RSS document if (!rss->errno && node->ns == NULL && xmlStrcmp(node->name, (xmlChar*)"rss")) rss->errno = RSS_E_FILE_NOT_RSS; // Get the version number if (!rss->errno && xmlHasProp(node, (xmlChar*)"version")) { char *version = (char*)xmlGetProp(node, (xmlChar*)"version"); rss->version = atof(version); free(version); if (rss->version != 0.91 && rss->version != 0.92 && rss->version != 2.0) rss->errno = RSS_E_FILE_NOT_RSS; } else if (!rss->errno) rss->errno = RSS_E_FILE_NOT_RSS; // Make sure the channel element exists if (!rss->errno && (node = node->children) != NULL && node->ns == NULL && xmlStrcmp(node->name, (xmlChar*)"channel")) rss->errno = RSS_E_FILE_NOT_RSS; // Get the various channel attributes rss->errno = !rss->errno ? rss_parse_channel(rss, doc, node) : rss->errno; }
HisDevValueBase* HisDevValueBase::Create(xmlNodePtr pNode) { STACK EDataType datatype; xmlChar* prop = NULL; if (xmlHasProp(pNode,PAR_DATATYPE)) { prop = xmlGetProp(pNode,PAR_DATATYPE); datatype = (EDataType)Converter::stoi((char*)prop); xmlFree(prop); switch(datatype) { case EDataType::Bool: return new HisDevValue<bool>(pNode,false); case EDataType::Double: return new HisDevValue<double>(pNode,0); case EDataType::Int: return new HisDevValue<int>(pNode,0); case EDataType::String: return new HisDevValue<string>(pNode,string("")); case EDataType::Uint: return new HisDevValue<uint32_t>(pNode,0); case EDataType::Unknown: return NULL; } } return NULL; }
static int parse_avt(elcgen *gen, xmlNodePtr n, const char *attr, expression **expr, int required, expression *pnode) { char *value; char *tmp; assert(pnode->xmlnode == n); if (!xmlHasProp(n,attr)) { *expr = NULL; if (required) return gen_error(gen,"%s element missing %s attribute",n->name,attr); else return 1; } value = xmlGetProp(n,attr); if (gen->ispattern && (!strncmp(value,"#E",2))) { *expr = new_expression(XPATH_DSVAR); (*expr)->str = strdup(value+1); } else { tmp = (char*)malloc(strlen(value)+3); sprintf(tmp,"}%s{",value); *expr = parse_xpath(gen,pnode,tmp); free(tmp); } free(value); return (NULL != *expr); }
string Funcionality::getValue() { string url=host+devicesURL+"/device/"+to_string<int>(id_padre)+"/read/"+getName(); string dev=""; xmlDocPtr doc; doc = xmlParseFile(url.c_str()); if (doc == NULL) { std::cerr<<"Error: imposible parsear "+url<<std::endl; exit(-1); } xmlNode *root = NULL; root = xmlDocGetRootElement(doc); if( !root || !root->name || xmlStrcmp(root->name,(const xmlChar *)"response") ) { xmlFreeDoc(doc); std::cerr<<"Error: No existe elemento root o problemas con la etiqueta de respuesta."<<std::endl; exit(-1); } xmlNode *cur_node, *child_node, *child_func; bool encontrado=false; for(cur_node = root->children; cur_node != NULL; cur_node = cur_node->next) { if ( cur_node->type == XML_ELEMENT_NODE && !xmlStrcmp(cur_node->name, (const xmlChar *) "value" )) { if(xmlHasProp(cur_node,(const xmlChar *) "type")) { if(strcmp((char *)xmlGetProp(cur_node,(xmlChar *)"type"),"error")==0) { dev="Error."; } else { dev=(char *)xmlNodeGetContent(cur_node); } } } } //xmlFreeNode(cur_node); //xmlFreeNode(child_node); //xmlFreeNode(root); //xmlFreeNode(child_func); //xmlFreeDoc(doc); xmlCleanupParser(); return dev; }
static gboolean infc_session_proxy_handle_user_join(InfcSessionProxy* proxy, InfXmlConnection* connection, xmlNodePtr xml, GError** error) { InfcSessionProxyPrivate* priv; InfSessionClass* session_class; GArray* array; InfUser* user; GParameter* param; guint i; priv = INFC_SESSION_PROXY_PRIVATE(proxy); session_class = INF_SESSION_GET_CLASS(priv->session); array = session_class->get_xml_user_props(priv->session, connection, xml); /* Set local flag if the join was requested by us (seq is present in * server response). */ param = inf_session_get_user_property(array, "flags"); g_assert(!G_IS_VALUE(¶m->value)); /* must not have been set already */ g_value_init(¶m->value, INF_TYPE_USER_FLAGS); if(xmlHasProp(xml, (const xmlChar*)"seq") != NULL) g_value_set_flags(¶m->value, INF_USER_LOCAL); else g_value_set_flags(¶m->value, 0); /* Set connection. If none was given, use publisher connection */ param = inf_session_get_user_property(array, "connection"); if(!G_IS_VALUE(¶m->value)) { g_value_init(¶m->value, INF_TYPE_XML_CONNECTION); g_value_set_object(¶m->value, G_OBJECT(connection)); } /* This validates properties */ user = inf_session_add_user( priv->session, (const GParameter*)array->data, array->len, error ); for(i = 0; i < array->len; ++ i) g_value_unset(&g_array_index(array, GParameter, i).value); g_array_free(array, TRUE); if(user != NULL) { infc_session_proxy_succeed_user_request(proxy, xml, user); return TRUE; } else { return FALSE; } }
/* * call-seq: * key?(attribute) * * Returns true if +attribute+ is set */ static VALUE key_eh(VALUE self, VALUE attribute) { xmlNodePtr node; Data_Get_Struct(self, xmlNode, node); if(xmlHasProp(node, (xmlChar *)StringValuePtr(attribute))) return Qtrue; return Qfalse; }
/* * call-seq: * remove_attribute(property) * * remove the property +property+ */ static VALUE remove_prop(VALUE self, VALUE property) { xmlNodePtr node; xmlAttrPtr attr ; Data_Get_Struct(self, xmlNode, node); attr = xmlHasProp(node, (xmlChar *)StringValuePtr(property)); if (attr) { xmlRemoveProp(attr); } return Qnil; }
// boolean hasAttribute(in DOMString name) raises(DOMException); static void _hasAttribute(Request& r, MethodParams& params) { const xmlChar* name=as_xmlname(r, params, 0); VXnode& vnode=GET_SELF(r, VXnode); xmlNode& element=get_self_element(vnode); // @todo: when name="xmlns" // write out result r.write_no_lang(VBool::get(xmlHasProp(&element, name)!=0)); }
bool SXmlNode::HasAttribute(const std::string& name) { if(!_node) return false; if(xmlHasProp(_node, (const xmlChar *)(name.c_str()))) return true; return false; }
/* * call-seq: * attribute(name) * * Get the attribute node with +name+ */ static VALUE attr(VALUE self, VALUE name) { xmlNodePtr node; xmlAttrPtr prop; Data_Get_Struct(self, xmlNode, node); prop = xmlHasProp(node, (xmlChar *)StringValuePtr(name)); if(! prop) return Qnil; return Nokogiri_wrap_xml_node((xmlNodePtr)prop); }
std::string getXmlStringProp(xmlNode* xmlNode, const char* xmlLabel, std::string defVal) { std::string value = defVal; if ( xmlHasProp(xmlNode, (xmlChar*) xmlLabel) ) { xmlChar* xc = xmlGetProp(xmlNode, (xmlChar*) xmlLabel); value = (char*) xc; xmlFree(xc); } return value; }
double getXmlDoubleProp(xmlNode* xmlNode, const char* xmlLabel, double defVal) { double value = defVal; if ( xmlHasProp(xmlNode, (xmlChar*) xmlLabel) ) { xmlChar* xc = xmlGetProp(xmlNode, (xmlChar*) xmlLabel); value = atof((const char*) xc); xmlFree(xc); } return value; }
bool Scene::getResponse(string url){ bool dev=false; xmlDocPtr doc; doc = xmlParseFile(url.c_str()); if (doc == NULL) { cerr<<"Error: imposible parsear "+url<<std::endl; exit(-1); } xmlNode *root = NULL; root = xmlDocGetRootElement(doc); string string_temp=""; if( !root || !root->name || xmlStrcmp(root->name,(const xmlChar *)"response") ) { xmlFreeDoc(doc); std::cerr<<"Error: No existe elemento root o problemas con la etiqueta de respuesta de scenes."<<std::endl; exit(-1); } xmlNode *cur_node; for(cur_node = root->children; cur_node != NULL; cur_node = cur_node->next) { if ( cur_node->type == XML_ELEMENT_NODE && !xmlStrcmp(cur_node->name, (const xmlChar *) "value" )) { if(xmlHasProp(cur_node,(const xmlChar *) "type")) { if(strcmp((char *)xmlGetProp(cur_node,(xmlChar *)"type"),"error")==0) { } else { string_temp=(char *)xmlNodeGetContent(cur_node); if(string_temp=="true") dev=true; } } } } xmlFreeDoc(doc); xmlCleanupParser(); return dev; }
const char *XMLAttr::getAttributeValue(const char *name) const { xmlNode *node = elem.getRealNode(); xmlAttr *attrs = xmlHasProp(node, (const xmlChar *)name); if (attrs) { return (const char *)attrs->children->content; } return 0; }
bool getXmlBoolProp(xmlNode* xmlNode, const char* xmlLabel, bool defVal) { bool value = defVal; if ( xmlHasProp(xmlNode, (xmlChar*) xmlLabel) ) { xmlChar* xc = xmlGetProp(xmlNode, (xmlChar*) xmlLabel); if ( !strcmp((const char*) xc, "1") || !strcmp((const char*) xc, "true") ) value = true; xmlFree(xc); } return value; }
Attr * element__attr( Element *el, unsigned char *attr_name, unsigned char *namespace_uri ) { xmlAttr *attr; if ( namespace_uri ) attr = xmlHasNsProp( ( xmlNode* ) el, attr_name, namespace_uri ) ; else attr = xmlHasProp( ( xmlNode* ) el, attr_name ) ; return ( Attr* ) attr ; }
/** * \fn double xml_node_get_float_with_default (xmlNode *node, \ * const xmlChar *prop, double default_value, int *error_code) * \brief Function to get a floating point number of a XML node property with a * default value. * \param node * \brief XML node. * \param prop * \brief XML property. * \param default_value * \brief default value. * \param error_code * \brief Error code. * \return Floating point number value. */ double xml_node_get_float_with_default (xmlNode * node, const xmlChar * prop, double default_value, int *error_code) { double x; if (xmlHasProp (node, prop)) x = xml_node_get_float (node, prop, error_code); else { x = default_value; *error_code = 0; } return x; }
const char *osync_xmlfield_get_attr(OSyncXMLField *xmlfield, const char *attr) { xmlAttrPtr prop; osync_assert(xmlfield); osync_assert(attr); prop = xmlHasProp(xmlfield->node, BAD_CAST attr); if(prop == NULL) return NULL; return (const char *)osync_xml_attr_get_content(prop); // return (const char *)prop->children->content; // return (const char *)xmlGetProp(xmlfield->node, BAD_CAST attr); }
/** * \fn int xml_node_get_uint_with_default (xmlNode *node, const xmlChar *prop, \ * unsigned int default_value, int *error_code) * \brief Function to get an unsigned integer number of a XML node property with * a default value. * \param node * \brief XML node. * \param prop * \brief XML property. * \param default_value * \brief default value. * \param error_code * \brief Error code. * \return Unsigned integer number value. */ unsigned int xml_node_get_uint_with_default (xmlNode * node, const xmlChar * prop, unsigned int default_value, int *error_code) { unsigned int i; if (xmlHasProp (node, prop)) i = xml_node_get_uint (node, prop, error_code); else { i = default_value; *error_code = 0; } return i; }
int assign_id_attributes(xmlDocPtr doc) { // Assume the ID attribute is one of (ID | Id | id) and tell this to libxml xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { xmlFreeDoc(doc); rb_raise(rb_eRuntimeError,"Error: unable to create new XPath context\n"); return(-1); } xmlChar* xpathExpr = "//*[@ID | @Id | @id]"; xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx); if(xpathObj == NULL) { xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); rb_raise(rb_eRuntimeError,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr); return(-1); } xmlNodeSetPtr nodes = xpathObj->nodesetval; int size = (nodes) ? nodes->nodeNr : 0; char* idNames[] = {"ID", "Id", "id"}; xmlAttrPtr attr, tmp; int i,j; for(i = 0; i < size; i++) { for(j=0; j<3;j++) { tmp = xmlHasProp(nodes->nodeTab[i], idNames[j]); if(tmp != NULL) attr = tmp; } if(attr == NULL) { xmlXPathFreeContext(xpathCtx); return(-1); } xmlChar* name = xmlNodeListGetString(doc, attr->children, 1); if(name == NULL) { xmlXPathFreeContext(xpathCtx); return(-1); } xmlAttrPtr tmp = xmlGetID(doc, name); if(tmp != NULL) { xmlFree(name); return 0; } xmlAddID(NULL, doc, name, attr); xmlFree(name); } xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); }