void _xml_endElementHandler(void *userData, const XML_Char *name) { XmlParser *parser = (XmlParser *)userData; char *tag_name; if (parser) { Variant retval; Array args = Array::Create(); tag_name = _xml_decode_tag(parser, (const char*)name); if (parser->endElementHandler) { args.append(parser); args.append(_xml_string_zval(tag_name)); xml_call_handler(parser, parser->endElementHandler, args); } if (!parser->data.isNull()) { Array tag; if (parser->lastwasopen) { parser->ctag.set("type","complete"); } else { tag = Array::Create(); _xml_add_to_info(parser,((char*)tag_name) + parser->toffset); tag.set("tag",String(((char*)tag_name) + parser->toffset, CopyString)); tag.set("type","close"); tag.set("level",parser->level); parser->data.append(tag); } parser->lastwasopen = 0; } free(tag_name); if (parser->ltags) { free(parser->ltags[parser->level-1]); } parser->level--; } }
void _xml_endElementHandler(void *userData, const XML_Char *name) { XmlParser *parser = (XmlParser *)userData; char *tag_name; if (parser) { Variant retval; Array args = Array::Create(); tag_name = _xml_decode_tag(parser, (const char*)name); if (parser->endElementHandler.toBoolean()) { args.append(parser); args.append(_xml_string_zval(tag_name)); xml_call_handler(parser, parser->endElementHandler, args); } if (!parser->data.isNull()) { if (parser->lastwasopen) { parser->ctag.toArrRef().set(s_type, s_complete); } else { ArrayInit tag(3); _xml_add_to_info(parser,((char*)tag_name) + parser->toffset); tag.set(s_tag, String(((char*)tag_name) + parser->toffset, CopyString)); tag.set(s_type, s_close); tag.set(s_level, parser->level); parser->data.toArrRef().append(tag.create()); } parser->lastwasopen = 0; } free(tag_name); if (parser->ltags) { free(parser->ltags[parser->level-1]); } parser->level--; } }
void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Char **attributes) { XmlParser *parser = (XmlParser *)userData; const char **attrs = (const char **) attributes; Variant retval; Array args = Array::Create(); if (parser) { parser->level++; char* tag_name = _xml_decode_tag(parser, (const char*)name); if (parser->startElementHandler) { args.append(parser); args.append(_xml_string_zval(tag_name)); args.append(Array::Create()); while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); args.lvalAt(2).set(String(att, AttachString), String(val, val_len, AttachString)); attributes += 2; } xml_call_handler(parser, parser->startElementHandler, args); } if (!parser->data.isNull()) { Array tag, atr; int atcnt = 0; tag = Array::Create(); atr = Array::Create(); _xml_add_to_info(parser,((char *) tag_name) + parser->toffset); tag.set(s_tag,String(((char *)tag_name)+parser->toffset,CopyString)); tag.set(s_type, s_open); tag.set(s_level, parser->level); parser->ltags[parser->level-1] = strdup(tag_name); parser->lastwasopen = 1; attributes = (const XML_Char **) attrs; while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); atr.set(String(att, AttachString), String(val, val_len, AttachString)); atcnt++; attributes += 2; } if (atcnt) { tag.set(s_attributes,atr); } parser->data.append(tag); parser->ctag.assignRef(parser->data.getArrayData()->endRef()); } free(tag_name); } }
void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Char **attributes) { XmlParser *parser = (XmlParser *)userData; const char **attrs = (const char **) attributes; Variant retval; Array args = Array::Create(); if (parser) { parser->level++; char* tag_name = _xml_decode_tag(parser, (const char*)name); if (parser->startElementHandler.toBoolean()) { args.append(parser); args.append(_xml_string_zval(tag_name)); args.append(Array::Create()); while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); args.lvalAt(2).toArrRef().set( String(att, AttachString), String(val, val_len, AttachString) ); attributes += 2; } xml_call_handler(parser, parser->startElementHandler, args); } if (!parser->data.isNull()) { if (parser->level <= XML_MAXLEVEL) { Array tag, atr; int atcnt = 0; tag = Array::Create(); atr = Array::Create(); _xml_add_to_info(parser,((char *) tag_name) + parser->toffset); tag.set(s_tag,String(((char *)tag_name)+parser->toffset,CopyString)); tag.set(s_type, s_open); tag.set(s_level, parser->level); parser->ltags[parser->level-1] = strdup(tag_name); parser->lastwasopen = 1; attributes = (const XML_Char **) attrs; while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); atr.set(String(att, AttachString), String(val, val_len, AttachString)); atcnt++; attributes += 2; } if (atcnt) { tag.set(s_attributes,atr); } auto& lval = parser->data.toArrRef().lvalAt(); lval.assignRef(tag); parser->ctag.assignRef(lval); } else if (parser->level == (XML_MAXLEVEL + 1)) { raise_warning("Maximum depth exceeded - Results truncated"); } } free(tag_name); } }