php - Add multiple attributes to a child in SimpleXMLElement -


i want add multiple attributes child in simplexmlelement this:

<data>     <photo>         <file size="3309519" size="jpg">p1270081</file>     </photo> </data> 

as right in code, can add 1 attribute per child code below shows.

$xml = new simplexmlelement('<data/>');  $photo = $xml->addchild('photo'); $photo->addchild('file', 'p1270081')->addattribute('size', '3309519'); $photo->addchild('uploaded', '2013-09-01 15:23:10')->addattribute('by', 'edgren'); 

if change third line $photo->addchild('file', 'p1270081')->addattribute('size', '3309519')->addattribute('type', 'jpg'); i'm getting error message:

fatal error: call member function addattribute() on non-object in ...

i new creating xml files on fly simplexmlelement don't know how shall fix issue. should fix it?

addattribute returns void. if want add more attributes have this:

$file = $photo->addchild('file', 'p1270081'); $file->addattribute('size', '3309519'); $file->addattribute('type', 'jpg'); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -