コード例 #1
0
ファイル: XPath.class.php プロジェクト: hoksi/Textcube
    if (!$xPath->importFromString($xmlSource)) {
        echo $xPath->getLastError();
        exit;
    }
    _title("Following was imported:");
    echo $xPath->exportAsHtml();
    _title("Get some content");
    echo "Last text part in &lt;AAA&gt;: '" . $xPath->wholeText('/AAA[1]', -1) . "'<br>\n";
    echo "All the text in  &lt;AAA&gt;: '" . $xPath->wholeText('/AAA[1]') . "'<br>\n";
    echo "The attibute value  in  &lt;BBB&gt; using getAttributes('/AAA[1]/BBB[1]', 'FOO'): '" . $xPath->getAttributes('/AAA[1]', 'FOO') . "'<br>\n";
    echo "The attibute value  in  &lt;BBB&gt; using getData('/AAA[1]/@FOO'): '" . $xPath->getData('/AAA[1]/@FOO') . "'<br>\n";
    _title("Append some additional XML below /AAA/BBB:");
    $xPath->appendChild('/AAA[1]/BBB[1]', '<CCC> Step 1. Append new node </CCC>', $afterText = FALSE);
    $xPath->appendChild('/AAA[1]/BBB[1]', '<CCC> Step 2. Append new node </CCC>', $afterText = TRUE);
    $xPath->appendChild('/AAA[1]/BBB[1]', '<CCC> Step 3. Append new node </CCC>', $afterText = TRUE);
    echo $xPath->exportAsHtml();
    _title("Insert some additional XML below <AAA>:");
    $xPath->reindexNodeTree();
    $xPath->insertChild('/AAA[1]/BBB[1]', '<BB> Step 1. Insert new node </BB>', $shiftRight = TRUE, $afterText = TRUE);
    $xPath->insertChild('/AAA[1]/BBB[1]', '<BB> Step 2. Insert new node </BB>', $shiftRight = FALSE, $afterText = TRUE);
    $xPath->insertChild('/AAA[1]/BBB[1]', '<BB> Step 3. Insert new node </BB>', $shiftRight = FALSE, $afterText = FALSE);
    echo $xPath->exportAsHtml();
    _title("Replace the last <BB> node with new XML data '&lt;DDD&gt; Replaced last BB &lt;/DDD&gt;':");
    $xPath->reindexNodeTree();
    $xPath->replaceChild('/AAA[1]/BB[last()]', '<DDD> Replaced last BB </DDD>', $afterText = FALSE);
    echo $xPath->exportAsHtml();
    _title("Replace second <BB> node with normal text");
    $xPath->reindexNodeTree();
    $xPath->replaceChildByData('/AAA[1]/BB[2]', '"Some new text"');
    echo $xPath->exportAsHtml();
}