0

I'm a beginner and I really need your help! I have an XML file to parse in PHP with a list of empty elements :

<?xml version="1.0" encoding="utf-16"?>
<elements attribute="value" attribute="value">
  <element attribute="value" attribute="value" attribute="value" />
  <element attribute="value" attribute="value" attribute="value" />
  <element attribute="value" attribute="value" attribute="value" />
  <element attribute="value" attribute="value" attribute="value" />
  ...
</elements>

How can I get the value of each attribute in the "element" nodes ? Thanks for your help!

bs7
  • 627
  • 4
  • 11
  • possible duplicate of [Best XML Parser for PHP](http://stackoverflow.com/questions/188414/best-xml-parser-for-php) – Pekka Dec 24 '11 at 12:46
  • there is no difference between getting attributes from empty element or non-empty elements. Also, since you are supposed to do research before asking please point out why none of http://stackoverflow.com/search?q=getting+attributes+xml+php helped answer your question. – Gordon Dec 24 '11 at 14:03

1 Answers1

0

Why you posted an invalid XML? Did you mean -

<?xml version="1.0" encoding="utf-8"?>
<elements attribute1="value" attribute2="value">
    <element attribute1="value" attribute2="value" attribute3="value" />
    <element attribute1="value" attribute2="value" attribute3="value" />
    <element attribute1="value" attribute2="value" attribute3="value" />
    <element attribute1="value" attribute2="value" attribute3="value" />
</elements>

In that case you SimpleXML (http://www.php.net/manual/en/simplexmlelement.attributes.php)

Rifat
  • 7,628
  • 4
  • 32
  • 46
  • lolz, you are new right :D? Don't know how to accept an answer. BTW, I'm happy that it helped :) – Rifat Dec 24 '11 at 15:13