RE: [PHP] looking for tutorial on XML parsing of attributes...
| From: | J. Scott Johnson | Date: | Sat, 23 Mar 2002 17:19:05 +0000 |
| Subject: | RE: [PHP] looking for tutorial on XML parsing of attributes... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-89842@lists.php.net to get a copy of this message | ||
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 = "<para><note 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:
* * * * * * * * * * * * * * * * * * * * * * * * * *
sjohnson@fuzzygroup.com
http://www.fuzzygroup.com/
Yahoo IM: fuzzygroup
-----Original Message-----
From: Erik Price [mailto:pricee@hhbrown.com]
Sent: Friday, March 22, 2002 3:43 PM
To: scott-brown@rogers.com
Cc: php-general@lists.php.net
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">
> <description>sometext</description>
> </status>
> <domain fqdn="fqdn-identidier1">
> <status code="some-numeric-code1">
> <description>sometext1</description>
> </status>
> </domain>
> <domain fqdn="fqdn-identidier2">
> <status code="some-numeric-code2">
> <description>sometext2</description>
> </status>
> </domain>
> <domain fqdn="fqdn-identidier3">
> <status code="some-numeric-code3">
> <description>sometext3</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
pricee@hhbrown.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php