php simplexmlelement get first element in one line

Posted by Senica Gonzalez on Stack Overflow See other posts from Stack Overflow or by Senica Gonzalez
Published on 2010-05-12T01:35:27Z Indexed on 2010/05/12 1:44 UTC
Read the original article Hit count: 275

Filed under:
|

Just trying to figure a shorter way to do this:

I'm using simpleXMLElement to parse an xml file and it's aggravating to have to call two lines to process an array when I know what node I want.

Current code:

$xml = new SimpleXMLElement($data);
$r = $xml->xpath('///givexNumber');
$result["cardNum"] = $r[0];

What I would like to do would be something like I can do with DomX

$result["cardNum"] = $xml->xpath('///givexNumber')->item(0)->nodeValue;

Any ideas?

I didn't really see that simplexmlelement can do this, but thought someone might know a trick or two.

© Stack Overflow or respective owner

Related posts about php

Related posts about simplexmlelement

  • SimpleXMLElement (PHP) throwing error on XML root attributes

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am working on a project that will take XML data submitted through a textarea input in a form then extract the data and throw it into a database. I am getting errors about the attribute in the root field of my XML (it is the same schema each time, but with different values). If i remove these attributes… >>> More

  • Parse a json(?) string using php

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I have a string, more specifically, this one: a:16:{s:9:"pseudonym";O:16:"SimpleXMLElement":0:{}s:14:"parallel_title";O:16:"SimpleXMLElement":0:{}s:9:"title_var";O:16:"SimpleXMLElement":0:{}s:6:"series";O:16:"SimpleXMLElement":0:{}s:9:"vol_title";O:16:"SimpleXMLElement":0:{}s:9:"reference";O:16:"SimpleXMLElement":0:{}s:10:"bound_with";O:16:"SimpleXMLElement":0:{}s:15:"general_remarks";O:16:"SimpleXMLElement":0:{}s:6:"copies";O:16:"SimpleXMLElement":1:{i:0;s:1:"1";}s:11:"remarks_BPH";O:16:"SimpleXMLElement":0:{}s:3:"ICN";O:16:"SimpleXMLElement":1:{i:0;s:4:"neen";}s:10:"provenance";O:16:"SimpleXMLElement":0:{}s:7:"binding";O:16:"SimpleXMLElement":0:{}s:10:"size_hxwxd";O:16:"SimpleXMLElement":0:{}s:6:"BookID";O:16:"SimpleXMLElement":1:{i:0;s:4:"6271";}s:5:"repro";O:16:"SimpleXMLElement":0:{}} Is… >>> More

  • Looping through a SimpleXML object, or turning the whole thing into an array.

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I'm trying to work out how to iterate though a returned SimpleXML object. I'm using a toolkit called Tarzan AWS, which connects to Amazon Web Services (SimpleDB, S3, EC2, etc). I'm specifically using SimpleDB. I can put data into the Amazon SimpleDB service, and I can get it back. I just don't know… >>> More

  • I don't get prices with Amazon Product Advertising API

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I try to get prices of an ASIN number with the Amazon Product Advertising API. Code: $artNr = "B003TKSD8E"; $base_url = "http://ecs.amazonaws.de/onca/xml"; $params = array( 'AWSAccessKeyId' => self::API_KEY, 'AssociateTag' => self::API_ASSOCIATE_TAG, 'Version'… >>> More

  • php xml SimpleXMLElement

    as seen on Stack Overflow - Search for 'Stack Overflow'
    <Placemark id="p1"></Placemark> <Placemark id="p2"></Placemark> <Placemark id="p3"></Placemark> <Placemark id="p4"></Placemark> hi,im using SimpleXMLElement in my php, my question is,how do i get placemark id 3? is that something like this ? $xml->Response->Placemark['id=3']->AddressDetails->Country->CountryName; thank… >>> More