0
     <Parent>
  <Children idontknowthis='thisisnotmyquestion'>
   <x>1</x>
   <x>2</x>
   <x>3</x>
   <x>4</x>
  </Children>
 </Parent>

Example an .xml file I'm working with below. My script would need to establish "id" by itself (to be clear I can already get bk109)...

   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems 
      of being quantum.</description>
   </book>

For the purpose of an XML import script in PHP which will import many different XML files. How do I obtain the attribute names? (i.e. "id")

3
  • 1
    Can you show us the code used to get bk109? Commented Jul 22, 2013 at 22:31
  • I was using something like... foreach( $xml5 as $header => $book ) { echo $book->attributes().'<br>'; } Commented Jul 22, 2013 at 22:41
  • 2
    This question appears to be off-topic because it is about reading about the topic in the manual (or using the search here on site). Commented Jul 23, 2013 at 13:40

1 Answer 1

1

Use SimpleXML's attributes property.

See http://php.net/manual/en/simplexmlelement.attributes.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.