[UPHPU] php + xml noob

Lonnie Olson fungus at aros.net
Fri Dec 17 11:28:23 MST 2004


On Dec 16, 2004, at 7:58 PM, Steve Dibb wrote:
> Has anyone here worked with parsing XML files in PHP before?
>
> Basically what I have is an XML file I want to get a value out of one 
> of the tags, and I have *no* idea where to start.  I'm looking at the 
> XML pages, and I'm a bit lost.
>
> All I'm trying to do is get "var" out of a structure similar to shis:
>
>    <xml_tag1>
>       <xml_tag2>var</xml_tag2>
>    </xml_tag1>
>
> Is there any _easy_ way to do that?  I hope?

If the XML file is small, and you are running PHP 4.2.1 or higher, you 
can use domxml_xmltree()

$xmldata = "
    <xml_tag1>
       <xml_tag2>var</xml_tag2>
    </xml_tag1>
";
$tree = domxml_xmltree($xmldata);

$var = $tree->children[0]->children[1]->children[0]->content;

print_r($tree);

--lonnie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2482 bytes
Desc: not available
Url : http://uphpu.org/pipermail/uphpu/attachments/20041217/e2699cdf/smime.bin


More information about the UPHPU mailing list