[ create a new paste ] login | about

Link: http://codepad.org/gJ1Y2LjM    [ raw code | output | fork ]

PHP, pasted on Dec 15:
<?php
$book = array('isbn'=>123456789099, 'title' => 'Harry Potter 2', 'author' => 'J K. Rowling', 'edition' => '2007');
$doc = new DOMDocument();
$doc->loadXML('<?xml version="1.0"?>
<books>
    <book>
        <isbn>123456789098</isbn>
        <title>Harry Potter</title>
        <author>J K. Rowling</author>
        <edition>2005</edition>
    </book>
</books>');
$fragment = $doc->createDocumentFragment();
$fragment->appendXML("    <book>
        <isbn>{$book['isbn']}</isbn>
        <title>{$book['title']}</title>
        <author>{$book['author']}</author>
        <edition>{$book['edition']}</edition>
    </book>
");
$doc->documentElement->appendChild($fragment);
echo $doc->saveXML();


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0"?>
<books>
    <book>
        <isbn>123456789098</isbn>
        <title>Harry Potter</title>
        <author>J K. Rowling</author>
        <edition>2005</edition>
    </book>
    <book>
        <isbn>123456789099</isbn>
        <title>Harry Potter 2</title>
        <author>J K. Rowling</author>
        <edition>2007</edition>
    </book>
</books>


Create a new paste based on this one


Comments: