Re: XML Extraction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Dec 17, 2007 10:44 PM, VamVan <vamseevan@xxxxxxxxx> wrote:

> Hello,
>
> I receive an output  as an  XML File. Please  provide some scripts that I
> can use for extraction of the values.
>
> For Example:
> <title>hello</title>
>
> <title>hello2</title>
>
> <title>hello3</title>
>
> are 3 different records in the XML File. How can I retrieve the result set
> in a loop and also sort it like DESC and ASC for example.
>
> While()
> {
>  xml['title'] // Value
> }
>


<?php
$xml=
<<<XML
<container>
        <title>i</title>
        <title>care</title>
        <title>about</title>
        <title>things</title>
        <arbitraryContent>xmlInPhpIsFun</arbitraryContent>
</container>
XML;

$simpleXmlElt = new SimpleXMLElement($xml);
$titleElements = $simpleXmlElt->xpath('//title');
foreach($titleElements as $curTitleElement) {
        echo $curTitleElement . PHP_EOL;
}
?>

no charge ;) hehe
-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux