simplexml


Get children attributes using simplexml


The xml data looks like this:
<feed>
<entry>
<abc:rank scheme="http://foo.bar">45</abc:rank>
<abc:rank scheme="http://foo2.bar">88</abc:rank>
</entry>
<entry>
<abc:rank scheme="http://foo.bar">125</abc:rank>
<abc:rank scheme="http://foo2.bar">32</abc:rank>
</entry>
</feed>
I am able to output all of these entries with this code:
foreach($xml->entry[$i]->children('abc', true) as $a) {
echo $a;
}
However, if I want to get the one with the content "88" in the first entry, something like
foreach($xml->entry[$i]->children('abc', true) as $a) {
if($a["scheme"] == "http://foo2.bar")
echo $a;
}
does not work.
How can I select these children depending on their attribute?
Ok I got it by now. For those interested in the correct solution:
$namespaces = $xml->entry[$i]->getNameSpaces('true');
$abc= $xml->entry[$i]->children($namespaces['abc']);
foreach($abc->rank as $a) {
$scheme = $a->attributes();
echo $scheme['scheme'];
echo " - ";
}

Related Links

warning: simplexml_load_file(): I/O warning : failed to load external entity drupal [closed]
What's wrong with this code? SimpleXMLElement [closed]
Get children attributes using simplexml
Select attribute in simplexml
Save formatted xml
SimpleXML (Zend_Config_Xml actually) and foreach : which tag am I iterating?
simplexml_load_file() error happening in only localhost/xampp
SimpleXml tar.gz
simplexml_load_file error in PHP 5.3
simplexml_load_file not a valid URI issue
Can't turn XML response into an simplexml object
Having trouble getting Fogbugz API response into a SimpleXML object
Upgraded to php 5.3.10 and simpleXMLelement is broken
Parsing RSS Feed with SimpleXML
php simplexml_load_file (script url) failed to open stream
PHP - SimpleXML not returning object

Categories

HOME
pandas
openmp
mediawiki
deezer
angular-material
hp-exstream
session
routes
cmd
webpack-2
ojdbc
onelogin
tomcat6
wheelnav.js
row
spring-tool-suite
designer
saxon
fatal-error
invantive-sql
openedx
web-sql
firebase-crash-reporting
neo4j-spatial
vision
google-rich-snippets
stormpath
grails-3.1
framemaker
asset-pipeline
openoffice.org
language-concepts
force-layout
appfabric
main
web-mining
gzipstream
nomethoderror
nxlog
heightmap
convertapi
btrace
chain-builder
revapi
jquery-nestable
winscp-net
integrity
setter
nativeapplication
carrot
tactic
google-perftools
pillow
flutterwave
android-fonts
grails-tomcat-plugin
infix-notation
probability-density
ctest
connect-by
angstrom-linux
ready-api
testng-dataprovider
dlna
netmq
freelancer.com-api
r-tree
ora-00900
tableau-online
microbenchmark
myo
graph-drawing
system32
p2
bridge.net
formatjs
jsonpickle
cctv
titanium-modules
php-5.4
xojo
navigationservice
funcunit
expected-exception
meteor-velocity
mcts
rabl
sqlperformance
pvrtc
twrequest
transactionscope
spyware
zpt
rfc1123
appender
calling-convention
krl
zend-translate
gin
bespin
sef
multiple-languages

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App