bool XMLReader::processNode() { if (m_reader == NULL) { std::cout << "error" << std::endl ; } if (xmlTextReaderRead(m_reader) != 1) { return false ; } m_attributes.clear() ; if (xmlTextReaderHasAttributes(m_reader) == 1) { int count = xmlTextReaderAttributeCount(m_reader) ; for (int i = 0 ; i < count ; i++) { xmlTextReaderMoveToAttributeNo(m_reader, i) ; m_attributes.insert( std::pair<std::string, std::string>( (char*) xmlTextReaderConstLocalName( m_reader), (char*) xmlTextReaderConstValue( m_reader))) ; } xmlTextReaderMoveToElement(m_reader) ; } // std::cout << print() << std::endl ; return true ; }
gint xml_reader_count_attributes (XmlReader *reader) { g_return_val_if_fail (XML_IS_READER (reader), FALSE); return xmlTextReaderAttributeCount (reader->xml); }
int BEXMLTextReader::number_of_attributes() { int count = xmlTextReaderAttributeCount ( reader ); if ( count == kBE_XMLReaderError ) { throw BEXMLReaderInterface_Exception ( last_error() ); } return count; }
//Parse AC flight plan xml (block & waypoint names void parse_ac_fp(int DevNameIndex, char *filename) { xmlTextReaderPtr reader; int ret; reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOWARNING | XML_PARSE_NOERROR); /* Dont validate with the DTD */ xmlChar *name, *value; if (reader != NULL) { ret = xmlTextReaderRead(reader); int wp_queue=1; int bl_queue=1; while (ret == 1) { name = xmlTextReaderName(reader); if (name == NULL) { name = xmlStrdup(BAD_CAST "--"); } //read waypoint names if (xmlStrEqual(name, (const xmlChar *)"waypoint")) { //waypoint node read name attr. xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"name"); value = xmlTextReaderValue(reader); //copy it to DevNames[] structure strcpy(DevNames[DevNameIndex].AcWp[wp_queue].Wp_Name, (char *) value); wp_queue++; } if (xmlStrEqual(name, (const xmlChar *)"block")) { //Read block names if ( xmlTextReaderAttributeCount(reader) >= 1 ) { xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"name"); value = xmlTextReaderValue(reader); strcpy(DevNames[DevNameIndex].AcBl[bl_queue].Bl_Name, (char *) value); bl_queue++; } } ret = xmlTextReaderRead(reader); } xmlFreeTextReader(reader); if (ret != 0) { if (verbose) { printf("App Server: failed to parse %s\n", filename); fflush(stdout); } } } else { if (verbose) { printf("App Server: Unable to open %s\n", filename); fflush(stdout); } } }
/* * call-seq: * attribute_count * * Get the number of attributes for the current node */ static VALUE attribute_count(VALUE self) { xmlTextReaderPtr reader; Data_Get_Struct(self, xmlTextReader, reader); int count = xmlTextReaderAttributeCount(reader); if(count == -1) return Qnil; return INT2NUM(count); }
static void processNode(xmlTextReaderPtr reader) { int type; type = xmlTextReaderNodeType(reader); if (count) { if (type == 1) { elem++; attrs += xmlTextReaderAttributeCount(reader); } } }
/* reader:attribute_count() */ static int xmlreader_attribute_count(lua_State *L) { xmlreader xr = check_xmlreader(L, 1); int ret = xmlTextReaderAttributeCount(xr); if (ret != -1) { lua_pushinteger(L, ret); return 1; } else { lua_pushnil(L); xmlreader_pusherror(L); return 2; } }
static void FetchAttributes(xmlTextReaderPtr reader,t_ctxt *ctxt) { int i; int attrCount = xmlTextReaderAttributeCount(reader); //printf("fetch xml attributes %d\n",attrCount); ctxt->atcount = 0; for (i = 0; i < attrCount && i < XOML_MAX_ATTR ; i++) { xmlChar *aqname = NULL; xmlChar *avalue = NULL; xmlTextReaderMoveToAttributeNo(reader,i); aqname = xmlTextReaderName(reader); avalue = xmlTextReaderValue(reader); ctxt->atname[ctxt->atcount] = (char *)aqname; ctxt->atvalue[ctxt->atcount] = (char *)avalue; ctxt->atcount++; } }
int XmlTextReader::get_AttributeCount() const { return XmlCheck(xmlTextReaderAttributeCount(ToReader(m_p))); }
/* @method Int XmlReader.getAttributeCount() */ METHOD XmlReader_getAttributeCount(Ctx *ctx, knh_sfp_t *sfp) { xmlTextReaderPtr reader = (xmlTextReaderPtr) p_cptr(sfp[0]); int ret = xmlTextReaderAttributeCount(reader); KNH_RETURN_Int(ctx,sfp,ret); }
/* * call-seq: * reader.attribute_count -> count * * Provide the number of attributes of the current node. */ static VALUE rxml_reader_attr_count(VALUE self) { return INT2FIX(xmlTextReaderAttributeCount(rxml_text_reader_get(self))); }
/* * call-seq: * reader.attribute_count -> count * * Provide the number of attributes of the current node. */ static VALUE rxml_reader_attr_count(VALUE self) { xmlTextReaderPtr xreader = rxml_text_reader_get(self); return INT2FIX(xmlTextReaderAttributeCount(xreader)); }
/*DEF*/void *XoReadXmlReader(/*xmlTextReaderPtr*/ void *preader,char *roottype,int flags,int *err) { xmlTextReaderPtr reader = (xmlTextReaderPtr)preader; int next; t_ctxt ctxt; int ret; *err = 0; memset (&ctxt,0,sizeof(ctxt)); ctxt.roottype = roottype; ctxt.flags = flags; ctxt.ns.flags = flags; _XoAllocCtxt(&ctxt); if ( C_PARSE_TARGET(&ctxt) ) { void *r; char *tag = "<dont_save_this_tag>"; r = _XoRootPush(NULL,&ctxt,NULL,tag,err); if (!r) { _XoFreeCtxt(&ctxt); return NULL; } _XoSetElementName(r,tag); *err = 0; } if ( !C_PARSE_TRACE(&ctxt) ) xmlTextReaderSetErrorHandler(reader,IgnoreTrace,NULL); ret = 1; next = xmlTextReaderRead(reader); while (next == 1 && ret > 0) { ctxt.depth = xmlTextReaderDepth(reader); ctxt.nodetype = xmlTextReaderNodeType(reader); ctxt.qname = (char *)xmlTextReaderName(reader); ctxt.value = (char *)xmlTextReaderValue(reader); switch (ctxt.nodetype) { case XML_READER_TYPE_ELEMENT : ctxt.isempty = xmlTextReaderIsEmptyElement(reader); ctxt.atcount = xmlTextReaderAttributeCount(reader); FetchAttributes(reader,&ctxt); break; case XML_READER_TYPE_TEXT : break; } ret = _XoProcessNode(reader,&ctxt); if (ctxt.atcount) _XoFreeAttributesWith(&ctxt,xmlFree); if (ctxt.qname) xmlFree(ctxt.qname); if (ctxt.value) xmlFree(ctxt.value); if (ret < 0) { ctxt.line = xmlTextReaderGetParserLineNumber(reader); goto errload; } next = xmlTextReaderRead(reader); if ( C_PARSE_INTERACTIF(&ctxt) ) { int c; switch(ctxt.prevnode) { case XML_READER_TYPE_ELEMENT : case XML_READER_TYPE_TEXT : case XML_READER_TYPE_END_ELEMENT : _XoDumpStack(&ctxt); fflush(stdin); c = getchar(); if (c == 'p') { void *o; o = ctxt.obj[ctxt.level-1]; XoSaveAscii(o,stdout); } break; } } } if (next != 0) // parsing error, get line number { *err = xmlTextReaderGetParserLineNumber(reader); } if (next != 0) { if ( C_PARSE_TRACE(&ctxt) ) XOML_TRACE("XoReadXmlReader() : failed to parse next=%d ret=%d line=%d\n", next,ret,*err); if (ctxt.obj[0]) XoFree(ctxt.obj[0],1); _XoFreeCtxt(&ctxt); return NULL; } errload : if (ret < 0) { *err = ret; if ( C_PARSE_TRACE(&ctxt) ) XOML_TRACE("XoReadXmlReader() : failed to load next=%d ret=%d line=%d\n", next,ret,ctxt.line); if (ctxt.obj[0]) XoFree(ctxt.obj[0],1); _XoFreeCtxt(&ctxt); return NULL; } _XoFreeCtxt(&ctxt); return ctxt.obj[0]; }
/******************************************************************** * FUNCTION get_all_attrs * * Copy all the attributes from the current node to * the xml_attrs_t queue * * INPUTS: * scb == session control block * errnode == element node to use for reporting errors * msghdr == msg hdr w/ Q to get any rpc-errors as found, * NULL if not used * nserr == TRUE if unknown namespace should cause the * function to fail and the attr not to be saved * This is the normal mode. * == FALSE and the namespace will be marked INVALID * but an error will not be returned * * OUTPUTS: * attrs Q contains 0 or more entries * *msghdr.errQ may have rpc-errors added to it * * RETURNS: * status of the operation * returns NO_ERR if all copied okay or even zero copied *********************************************************************/ static status_t get_all_attrs (ses_cb_t *scb, xml_node_t *errnode, xml_attrs_t *attrs, ncx_layer_t layer, xml_msg_hdr_t *msghdr, boolean nserr) { /* check the attribute count first */ int cnt = xmlTextReaderAttributeCount(scb->reader); if (cnt==0) { return NO_ERR; } const xmlChar *name = NULL; status_t res = NO_ERR; boolean xpatherror = FALSE; int ret = 0; /* move through the list of attributes */ int i = 0; boolean done = FALSE; for (; i < cnt && !done; i++) { xmlChar *value = NULL; const xmlChar *badns = NULL; uint32 plen = 0; xmlns_id_t nsid = 0; res = NO_ERR; name = NULL; /* get the next attribute */ if (i==0) { ret = xmlTextReaderMoveToFirstAttribute(scb->reader); } else { ret = xmlTextReaderMoveToNextAttribute(scb->reader); } if (ret != 1) { res = ERR_XML_READER_INTERNAL; done = TRUE; } else { /* get the attribute name */ name = xmlTextReaderConstName(scb->reader); if (!name) { res = ERR_XML_READER_NULLNAME; } else { res = xml_check_ns(scb->reader, name, &nsid, &plen, &badns); if (!nserr && res != NO_ERR) { /* mask invalid namespace as requested */ nsid = xmlns_inv_id(); plen = 0; res = NO_ERR; } /* get the attribute value even if a NS error */ value = xmlTextReaderValue(scb->reader); if (!value) { res = ERR_XML_READER_NULLVAL; } else { /* save the values as received, may be QName * only error that can occur is a malloc fail */ xml_attr_t *attr = xml_add_qattr(attrs, nsid, name, plen, value, &res); if (!attr) { res = ERR_INTERNAL_MEM; } else { /* special hack: do not know which * attributes within an XML node * are tagged as XPath strings at this point * To save resources, only the 'select' and * 'key' attributes are supported at this time. */ if (!xml_strcmp(&name[plen], NCX_EL_SELECT)) { res = NO_ERR; attr->attr_xpcb = agt_new_xpath_pcb(scb, value, &res); if (!attr->attr_xpcb) { ; /* res already set */ } else { /* do a first pass parsing to resolve all * the prefixes and check well-formed XPath */ xpath_result_t *result = xpath1_eval_xmlexpr(scb->reader, attr->attr_xpcb, NULL, NULL, FALSE, FALSE, &res); if (res != NO_ERR) { xpatherror = TRUE; } xpath_free_result(result); } } else if (!xml_strcmp(&name[plen], NCX_EL_KEY)) { res = NO_ERR; attr->attr_xpcb = agt_new_xpath_pcb(scb, value, &res); if (!attr->attr_xpcb) { ; /* res already set */ } else { res = xpath_yang_validate_xmlkey (scb->reader, attr->attr_xpcb, NULL, FALSE); if (res != NO_ERR) { xpatherror = TRUE; } } } } } } } /* check the result */ if (res != NO_ERR && msghdr) { /* need a dummy attribute struct to report this error */ xml_attr_t errattr; memset(&errattr, 0x0, sizeof(xml_attr_t)); errattr.attr_ns = xmlns_nc_id(); errattr.attr_qname = name; errattr.attr_name = name; errattr.attr_val = value; /* save the error info */ if (xpatherror) { res = ERR_NCX_INVALID_XPATH_EXPR; /* generate an invalid-value error */ agt_record_attr_error(scb, msghdr, layer, res, &errattr, errnode, NULL, NCX_NT_NONE, NULL); } else if (res==ERR_XML_READER_NULLVAL || res==ERR_NCX_UNKNOWN_NAMESPACE) { /* generate a bad namespace error */ agt_record_attr_error(scb, msghdr, layer, res, &errattr, errnode, badns, NCX_NT_NONE, NULL); } else { /* generate a generic error */ agt_record_attr_error(scb, msghdr, layer, res, &errattr, errnode, NULL, NCX_NT_NONE, NULL); } } if (value) { xmlFree(value); } } /* reset the current node to where we started */ ret = xmlTextReaderMoveToElement(scb->reader); if (ret != 1) { if (msghdr) { res = ERR_XML_READER_INTERNAL; agt_record_error(scb, msghdr, layer, res, errnode, NCX_NT_STRING, name, NCX_NT_NONE, NULL); } } return res; } /* get_all_attrs */
//## @Native int XmlReader.getAttributeCount(); static KMETHOD XmlReader_getAttributeCount(KonohaContext *kctx, KonohaStack *sfp) { xmlTextReaderPtr reader = getRawXmlReader(sfp[0]); int ret = (reader != NULL) ? xmlTextReaderAttributeCount(reader) : 0; KReturnUnboxValue(ret); }
Boolean_t tgt_node_process(xmlTextReaderPtr r, tgt_node_t **node) { const xmlChar *name; const xmlChar *value; char **ap; xmlElementType node_type; tgt_node_t *n; tgt_node_t *an; n = *node; if (n == NULL) { n = node_alloc(); if (n == NULL) return (False); *node = n; } name = (xmlChar *)xmlTextReaderConstName(r); if (name == NULL) { node_free(n); *node = NULL; return (False); } node_type = (xmlElementType)xmlTextReaderNodeType(r); value = (xmlChar *)xmlTextReaderConstValue(r); if (node_type == XML_ELEMENT_NODE) { if (n->x_state != NodeAlloc) { n = node_child(n); *node = n; if (n == NULL) return (False); } if (xmlTextReaderAttributeCount(r) > 0) { for (ap = common_attr_list; *ap; ap++) { value = xmlTextReaderGetAttribute(r, (xmlChar *)*ap); if (value != NULL) { if ((an = node_alloc_attr(n)) == NULL) return (False); if (node_name(an, (xmlChar *)*ap) == False) { node_free(an); return (False); } if (node_value(an, value, True) == False) { node_free(an); return (False); } free((char *)value); } } } if (node_name(n, name) == False) { node_free(n); *node = NULL; return (False); } } else if ((value != NULL) && (node_type == XML_TEXT_NODE)) { if (node_value(n, value, True) == False) { node_free(n); *node = NULL; return (False); } } else if (node_type == XML_ELEMENT_DECL) { n = node_parent(n); if (n == NULL) return (False); *node = n; } else if (node_type == XML_COMMENT_NODE) { n = node_child(n); if (node_name(n, (xmlChar *)XML_COMMENT_STR) == False) { node_free(n); *node = NULL; return (False); } if (node_value(n, (xmlChar *)value, False) == False) { node_free(n); *node = NULL; return (False); } } else if (node_type != XML_DTD_NODE) { node_free(n); *node = NULL; return (False); } return (True); }
static dbus_bool_t xml_text_start_element (BusConfigParser *parser, xmlTextReader *reader, DBusError *error) { const char *name; int n_attributes; const char **attribute_names, **attribute_values; dbus_bool_t ret; int i, status, is_empty; _DBUS_ASSERT_ERROR_IS_CLEAR (error); ret = FALSE; attribute_names = NULL; attribute_values = NULL; #ifdef __SYMBIAN32__ name = (const char *) xmlTextReaderConstName (reader); #else name = xmlTextReaderConstName (reader); #endif n_attributes = xmlTextReaderAttributeCount (reader); is_empty = xmlTextReaderIsEmptyElement (reader); if (name == NULL || n_attributes < 0 || is_empty == -1) { _DBUS_MAYBE_SET_OOM (error); goto out; } attribute_names = dbus_new0 (const char *, n_attributes + 1); attribute_values = dbus_new0 (const char *, n_attributes + 1); if (attribute_names == NULL || attribute_values == NULL) { _DBUS_SET_OOM (error); goto out; } i = 0; while ((status = xmlTextReaderMoveToNextAttribute (reader)) == 1) { _dbus_assert (i < n_attributes); #ifdef __SYMBIAN32__ attribute_names[i] = (const char *) xmlTextReaderConstName (reader); attribute_values[i] = (const char *) xmlTextReaderConstValue (reader); #else attribute_names[i] = xmlTextReaderConstName (reader); attribute_values[i] = (xmlTextReaderConstValue (reader); #endif if (attribute_names[i] == NULL || attribute_values[i] == NULL) { _DBUS_MAYBE_SET_OOM (error); goto out; } i++; } if (status == -1) { _DBUS_MAYBE_SET_OOM (error); goto out; } _dbus_assert (i == n_attributes); ret = bus_config_parser_start_element (parser, name, attribute_names, attribute_values, error); if (ret && is_empty == 1) ret = bus_config_parser_end_element (parser, name, error); out: dbus_free (attribute_names); dbus_free (attribute_values); return ret; }