Jump to content

Add attribute to the element in xml


HardCoreMore

Recommended Posts

How can i add attribute at the same time when i am createing new element.

This is code for creating new element.

$book = simplexml_load_file('user.xml');
$dom = dom_import_simplexml($book);
$dom->appendChild(new DOMElement("user", "New Value"));

How can i add attribute to this new user element when i  create it?

 

This is xml

<?xml version="1.0"?>
<root>

<user id="34">
<pic>value</pic>
<pic>value</pic>
<pic>value</pic>
</user>



<userid="45">
<pic>value</pic>
<pic>value</pic>
<pic>value</pic>
</user>

<user id="22">
<pic>value</pic>
<pic>value</pic>
<pic>value</pic>
</user>

</root>

 

Please help i searched the web but i really can't find it.

Link to comment
https://forums.phpfreaks.com/topic/127560-add-attribute-to-the-element-in-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.