Re: XML Extraction
| From: | Nathan Nobbe | Date: | Tue, 18 Dec 2007 04:24:28 +0000 |
| Subject: | Re: XML Extraction | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-266004@lists.php.net to get a copy of this message | ||
On Dec 17, 2007 10:44 PM, VamVan <vamseevan@gmail.com> 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