Re: Adressing XML Objects
| From: | Nathan Rixham | Date: | Thu, 08 Jan 2009 23:44:32 +0000 |
| Subject: | Re: Adressing XML Objects | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-285777@lists.php.net to get a copy of this message | ||
Nathan Nobbe wrote:
On Thu, Jan 8, 2009 at 4:38 PM, Nathan Rixham <nrixham@gmail.com <mailto:nrixham@gmail.com>> wrote:Nathan Nobbe wrote:On Thu, Jan 8, 2009 at 4:02 PM, Merlin Morgenstern <merlin_x@fastmail.fm <mailto:merlin_x@fastmail.fm>>wrote:Hello nathan,I am unsing simplexml as it looks really simple :-) However, I could still not figure out how to adress data inside tags with attributes. For example:<anhang location="INTERN" gruppe="TITELBILD"> <data>bla blub</data>$xml->anhang[intern][titelbild]->data will not work.again, ill need some clarification. are you trying to get the data node directly, OR, are you trying to get the contents of all nodes which are descendants of anhang nodes, w/ attributes location and gruppe, having values INTERN and TITLEBILD respectively?these are two different the things, the former being, well simple$xml->anhang->datathe latter i would do via xpath, which SimpleXML supports as well.-nathanI think you hit the nail on the head with XPath nathan;//anhang[@location='INTERN' and @gruppe='TITELBILD']/datawhich would be requiring DOMDocument and DOMXPathive been really lazy about testing stuff first today :), but why not just rock it out w/ SimpleXML, $xml = new SimpleXMLElement($xmlstr); $searchResult = $xml->xpath('//anhang[@location='INTERN' and @gruppe='TITELBILD']/data'); at least im just saying you dont NEED DOMDocument & DOMXPath, but def, that is an alternative to SimpleXML. -nathan nice clarification namesake - I've always just dived right in to DOMDocuments and never gave simplexml much weight; but that's no reflection on simplexml :p