Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14174
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Extracting values from xml file using php/xpath/namespace/simplexml/ |
| Date | 2014-08-14 10:06 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <lsifpn$e83$1@dont-email.me> (permalink) |
| References | <a8eb7607-8c39-4062-917c-d815b223a021@googlegroups.com> <lsfp0k$cpj$1@dont-email.me> <b2d1ddf1-3b88-4f33-9336-d5f77ea186f4@googlegroups.com> |
On 8/14/2014 6:29 AM, ofuuzo@gmail.com wrote:
> kl. 15:25:41 UTC+2 onsdag 13. august 2014 skrev Jerry Stuckle følgende:
>> On 8/13/2014 7:02 AM, ofuuzo@gmail.com wrote:
>>
>>> Hi,
>>
>>> I am new in PHP/XML. I can't figure out how to combine xpath/namespace/simplexml/php to extract the values of "dc.title" and "dc.date" in this xml file:
>>
>>>
>>
>>> <?xml version="1.0" encoding="UTF-8"?> -<OAI-PMH xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd" xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>
>>> <ListRecords>
>>
>>> <record>
>>
>>> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/">
>>
>>> <oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/">
>>
>>> <dc:title>GAFBone</dc:title>
>>
>>> <dc:date>2014-05-01T00:00:00Z</dc:date>
>>
>>> </oai_dc:dc>
>>
>>>
>>
>>> </metadata>
>>
>>>
>>
>>> </record>
>>
>>> <record>
>>
>>> ......
>>
>>> </record>
>>
>>>
>>
>>> ....
>>
>>>
>>
>>> I need help.
>>
>>> Thank in advance.
>>
>>>
>>
>>> -Ofuuzo
>>
>>>
>>
>>
>>
>> What have you tried so far? What was the result?
>>
>>
>>
>> --
>>
>> ==================
>>
>> Remove the "x" from my email address
>>
>> Jerry Stuckle
>>
>> jstucklex@attglobal.net
>>
>> ==================
>
> I figured it out and it works:
>
> <?php
>
> $dom = new DOMDocument();
> $dom->load('http://doaj.org/oai?verb=ListRecords&from=2004-03-01&metadataPrefix=oai_dc&identifier=oai:2305-6754');
> $xpath = new DOMXpath($dom);
>
> $xpath->registerNamespace('oai', 'http://www.openarchives.org/OAI/2.0/');
> $xpath->registerNamespace('oai-dc', 'http://www.openarchives.org/OAI/2.0/oai_dc/');
> $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
>
> $records = $xpath->evaluate('/oai:OAI-PMH/oai:ListRecords/oai:record', NULL, FALSE);
> foreach ($records as $entry) {
> echo $xpath->evaluate('string(oai:header/oai:identifier)', $entry, FALSE);
> echo "\n";
> echo $xpath->evaluate('string(oai:header/oai:datestamp)', $entry, FALSE);
> echo "\n";
>
> $dc = $xpath->evaluate('oai:metadata/oai-dc:dc/dc:*', $entry, FALSE);
> foreach ($dc as $dcElement){
> switch ($dcElement->localName) {
> case 'title' :
> echo 'Title: '.$dcElement->nodeValue;
> echo "\n";
> break;
> case 'date' :
> echo 'Date: '.$dcElement->nodeValue;
> echo "\n";
> break;
> case 'relation' :
> echo 'Relation: '.$dcElement->nodeValue;
> echo "\n";
> break;
>
> }
> }
> }
> ?>
>
Great!
The DOM functions are a bit more complicated than simpleXML, but I like
them better. And once you get into it, it's not all that hard.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Extracting values from xml file using php/xpath/namespace/simplexml/ ofuuzo@gmail.com - 2014-08-13 04:02 -0700
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-13 09:25 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ ofuuzo@gmail.com - 2014-08-14 03:29 -0700
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-14 10:06 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-17 19:43 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-17 15:21 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-17 23:41 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-17 18:57 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-09-03 23:10 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-03 20:11 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-09-04 02:42 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-03 21:57 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-09-04 23:21 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-04 20:43 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-09-05 04:08 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-05 02:50 +0000
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-05 08:24 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-09-07 11:57 +0200
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-07 09:54 -0400
Re: Extracting values from xml file using php/xpath/namespace/simplexml/ "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-09-07 23:53 +0200
csiph-web