simplexml


Using XML node names with hyphens in PHP [duplicate]


This question already has an answer here:
SimpleXML Reading node with a hyphenated name
1 answer
I am trying to extract some data from XML but when I execute the following I get a
Warning: Invalid argument supplied for foreach() in ...
Code Example:
foreach ($xml->custom-field-value as $milestone)
{
...
}
It works fine for node names that are single words so I am guessing that it doesn't like the hyphens. Do I need to escape them and if so how?
From PHP manual:
Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.
In your case you do:
$xml->{'custom-field-value'}

Related Links

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
Having trouble processing XML with PHP SimpleXML
Simplexml How to access all element of the same node
simplexml_load_file failed to open stream Http request failed
Using XML node names with hyphens in PHP [duplicate]
SimpleXML Reading node with a hyphenated name

Categories

HOME
osgi
bluetooth
isabelle
gremlin
fluentd
single-sign-on
pycharm
onedrive
relayjs
survey
icloud
alpha
azure-media-services
pheatmap
contact
synchronization
medical
maude-system
jplayer
moonmail
task
size
visual-studio-2005
quickfix
iron-router
finite-automata
invantive-sql
text-rendering
lldb
object-detection
clickonce
errorlevel
arabic
chromium-embedded
pass-by-reference
javacv
underflow
apache-commons-io
poltergeist
entitlements
ping
facebook-apps
libuv
nat
yadcf
semantic-versioning
contact-form
mozilla
google-api-nodejs-client
wixsharp
libvpx
powershell-dsc
eigenvalue
estimote
turbogears
parentheses
network-flow
dds
paxos
sage-one
domain-model
return-value
sqlclient
font-size
media-player
color-profile
pycaffe
watchconnectivity
setuptools
firmata
passport-google-oauth
database-optimization
intrusion-detection
etsy
impresspages
jwplayer7
qcustomplot
hexdump
livequery
pagerank
srand
maven-tomcat-plugin
t4mvc
android-listview
riak-cs
tableau-online
sankey-diagram
bridge.net
clicktag
document-classification
openexr
android-radiobutton
eol
industrial
tidy
google-cloud-save
jplaton
eventual-consistency
angularjs-controller
pvrtc
hosts-file
appconkit
gcj
subgurim-maps
blackberry-playbook
invite
yui-datatable
sql-server-profiler
iphone-web-app
createwindow
asp.net-profiles
database-management
zend-tool
ti-dsp
ugc
uiq3

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