how to add attribute in xml packet
Posted: Fri Dec 10, 2010 8:46 am
Hi everyone,
I am new to this PHP programming.
I wanted to frame the following XML packet:
It is framing the basic packet with nodes but i am not able to add the attributes like title = "novel" to child 'id'.
Can anyone help me?
Thanks a lot for your kind help.
with regards
Praveen.
I am new to this PHP programming.
I wanted to frame the following XML packet:
I have written the following code:<books store="Sapna">
<book>
<id>title = "novel" cost = "125"</id>
</book>
</books>
Code: Select all
//Creates XML string and XML document using the DOM
$dom = new DomDocument('1.0');
//add root - <books>
$books = $dom->appendChild($dom->createElement('books'));
//add <book> element to <books>
$book = $books->appendChild($dom->createElement('book'));
//add <id> element to <book>
$id = $book->appendChild($dom->createElement('id')); Can anyone help me?
Thanks a lot for your kind help.
with regards
Praveen.