[ create a new paste ] login | about

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

PHP, pasted on Mar 15:
<?php

    $xmlData = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
     <configdata>
        <records>
             <somekey>
                <record>
                    <firstname>Jonathan</firstname>
                    <lastname>Kushner</lastname>
                </record>
                <record>
                    <firstname>Dustin</firstname>
                    <lastname>Kushner</lastname>
                </record>
                <record>
                    <firstname>Cameron</firstname>
                    <lastname>Kushner</lastname>
                </record>
            </somekey>
        </records>
    </configdata>
XML;

    // Create the document object
    $doc = new DOMDocument;

    // This is required in order to ignore the pretty-print whitspace
    $doc->preserveWhiteSpace = false;

    // load the data into the object
    $doc->loadXML($xmlData);
    $xpath = new DOMXpath($doc);

    $result = array();

    // Get the text nodes and loop them
    foreach ($xpath->query('//text()') as $record) {
        $result[] = $record->data;
    }

    print_r($result);


Output:
1
2
3
4
5
6
7
8
9
Array
(
    [0] => Jonathan
    [1] => Kushner
    [2] => Dustin
    [3] => Kushner
    [4] => Cameron
    [5] => Kushner
)


Create a new paste based on this one


Comments: