RE: [PHP] looking for tutorial on XML parsing of attributes...
If you use xml_parse_into_struct, it does split out the attributes into the array it creates. I tested this with the standard manual code, adding a single attribute to the sample data i.e. $simple = paranote attrib=\scott\simple note/note/para; $p = xml_parser_create(); xml_parse_into_struct($p,$simple,$vals,$index); xml_parser_free($p); echo Index array\n; print_r($index); echo \nVals array\n; print_r($vals); I got back: Index array Array ( [PARA] = Array ( [0] = 0 [1] = 2 ) [NOTE] = Array ( [0] = 1 ) ) Vals array Array ( [0] = Array ( [tag] = PARA [type] = open [level] = 1 ) [1] = Array ( [tag] = NOTE [type] = complete [level] = 2 [attributes] = Array ( [ATTRIB] = scott ) [value] = simple note ) [2] = Array ( [tag] = PARA [type] = close [level] = 1 ) ) There seems to be an attributes array which you can access (disclaimer - I haven't done that yet). http://www.php.net/manual/en/function.xml-parse-into-struct.php Scott Virtual: * * * * * * * * * * * * * * * * * * * * * * * * * * [EMAIL PROTECTED] http://www.fuzzygroup.com/ Yahoo IM: fuzzygroup -Original Message- From: Erik Price [mailto:[EMAIL PROTECTED]] Sent: Friday, March 22, 2002 3:43 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] looking for tutorial on XML parsing of attributes... I'm no expert on the XML functions, but post your code and maybe we can figure out what's wrong. Erik On Thursday, March 21, 2002, at 09:24 PM, Scott Brown wrote: Ok - first off, I've found a few... phpbuilder has a nice number of references. But every one I've tried has ignored attributes... either that, or I dont understand what I'm doing. I retrieve from a distant server an XML response to an inquiry: ?xml version=1.0 ? response version=1.0 requestid=some-request-identifier status code=some-numeric-code descriptionsometext/description /status domain fqdn=fqdn-identidier1 status code=some-numeric-code1 descriptionsometext1/description /status /domain domain fqdn=fqdn-identidier2 status code=some-numeric-code2 descriptionsometext2/description /status /domain domain fqdn=fqdn-identidier3 status code=some-numeric-code3 descriptionsometext3/description /status /domain /response BUT... when I parse this using xml_parse, all I'm getting out is: Name = RESPONSE -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array I cant seem to nail down how to pull the actual attribute values does anyone know of a tutorial that's going to teach me how to pull those attributes of fqdn and code? I've figured out how to get the DESCRIPTION... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] looking for tutorial on XML parsing of attributes...
Thanks - using xml_parse_into_struct does make parsing the document much easier... great suggestion. What I've ended up with is: // create parser $xp = xml_parser_create(); xml_parse_into_struct($xp,$xml,$vals,$index); xml_parser_free($xp); $found_domain = 0; $results = array(); for($ctr=0; $ctrcount($vals); $ctr++) { switch($vals[$ctr][tag]) { case DOMAIN: $found_domain = 1; break; case STATUS: if ($found_domain == 1) { array_push($results,$vals[$ctr][attributes][CODE]); } break; case DESCRIPTION: if ($found_domain == 1) array_push($results,$vals[$ctr][value]); break; } } echo Return Status = . $results[0] . BR\n; echo Return Desc = . $results[1] . BR\n; print_r($results); which then gives me (for something similar to the XMLdoc below): Return Status = 05BR Return Desc = Successfully added,eh?BR Array ( [0] = some-numeric-code1 [1] = sometext1 [2] = [3] = [4] = [5] = some-numeric-code2 [6] = sometext2 [7] = [8] = [9] = [10] = some-numeric-code3 [11] = sometext3 [12] = [13] = [14] = ) So I know that every grouping of 5 elements within the results array is associated with a given domain. (The two that are present are what I want...what are the others - just remnants of the tree traversal??) A little more fiddling, and I'll be able to pull it all apart as needed. This will do me for now though... But of course, my next question has to be isnt there an easier way to extract elements from the XML document? -Original Message- From: J. Scott Johnson [mailto:[EMAIL PROTECTED]] Sent: March 23, 2002 12:19 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: [PHP] looking for tutorial on XML parsing of attributes... If you use xml_parse_into_struct, it does split out the attributes into the array it creates. I tested this with the standard manual code, adding a single attribute to the sample data i.e. $simple = paranote attrib=\scott\simple note/note/para; $p = xml_parser_create(); xml_parse_into_struct($p,$simple,$vals,$index); xml_parser_free($p); echo Index array\n; print_r($index); echo \nVals array\n; print_r($vals); I got back: Index array Array ( [PARA] = Array ( [0] = 0 [1] = 2 ) [NOTE] = Array ( [0] = 1 ) ) Vals array Array ( [0] = Array ( [tag] = PARA [type] = open [level] = 1 ) [1] = Array ( [tag] = NOTE [type] = complete [level] = 2 [attributes] = Array ( [ATTRIB] = scott ) [value] = simple note ) [2] = Array ( [tag] = PARA [type] = close [level] = 1 ) ) There seems to be an attributes array which you can access (disclaimer - I haven't done that yet). http://www.php.net/manual/en/function.xml-parse-into-struct.php Scott Virtual: * * * * * * * * * * * * * * * * * * * * * * * * * * [EMAIL PROTECTED] http://www.fuzzygroup.com/ Yahoo IM: fuzzygroup -Original Message- From: Erik Price [mailto:[EMAIL PROTECTED]] Sent: Friday, March 22, 2002 3:43 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] looking for tutorial on XML parsing of attributes... I'm no expert on the XML functions, but post your code and maybe we can figure out what's wrong. Erik On Thursday, March 21, 2002, at 09:24 PM, Scott Brown wrote: Ok - first off, I've found a few... phpbuilder has a nice number of references. But every one I've tried has ignored attributes... either that, or I dont understand what I'm doing. I retrieve from a distant server an XML response to an inquiry: ?xml version=1.0 ? response version=1.0 requestid=some-request-identifier status code=some-numeric-code descriptionsometext/description /status domain fqdn=fqdn-identidier1 status code=some-numeric-code1 descriptionsometext1/description /status /domain domain fqdn=fqdn-identidier2 status code=some-numeric-code2 descriptionsometext2/description /status /domain domain fqdn=fqdn-identidier3 status code=some-numeric-code3 descriptionsometext3/description /status /domain /response BUT... when I parse this using xml_parse, all I'm getting out is: Name = RESPONSE -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array I cant seem to nail down how to pull the actual attribute values does anyone know of a tutorial that's going to teach me how to pull those
Re: [PHP] looking for tutorial on XML parsing of attributes...
I'm no expert on the XML functions, but post your code and maybe we can figure out what's wrong. Erik On Thursday, March 21, 2002, at 09:24 PM, Scott Brown wrote: Ok - first off, I've found a few... phpbuilder has a nice number of references. But every one I've tried has ignored attributes... either that, or I dont understand what I'm doing. I retrieve from a distant server an XML response to an inquiry: ?xml version=1.0 ? response version=1.0 requestid=some-request-identifier status code=some-numeric-code descriptionsometext/description /status domain fqdn=fqdn-identidier1 status code=some-numeric-code1 descriptionsometext1/description /status /domain domain fqdn=fqdn-identidier2 status code=some-numeric-code2 descriptionsometext2/description /status /domain domain fqdn=fqdn-identidier3 status code=some-numeric-code3 descriptionsometext3/description /status /domain /response BUT... when I parse this using xml_parse, all I'm getting out is: Name = RESPONSE -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array Name = DOMAIN -- Attributes = Array Name = STATUS -- Attributes = Array Name = DESCRIPTION -- Attributes = Array I cant seem to nail down how to pull the actual attribute values does anyone know of a tutorial that's going to teach me how to pull those attributes of fqdn and code? I've figured out how to get the DESCRIPTION... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php