コード例 #1
0
ファイル: XPath.class.php プロジェクト: hoksi/Textcube
      ..1.. <![CDATA[ bla  bla
      newLine blo blo ]]>
      <BBB foo="bar">
        ..2..
      </BBB>..3..<CC/>   ..4..</AAA>
EOD;
    // The sample code:
    $xmlOptions = array(XML_OPTION_CASE_FOLDING => TRUE, XML_OPTION_SKIP_WHITE => TRUE);
    $xPath = new XPath(FALSE, $xmlOptions);
    //$xPath->bDebugXmlParse = TRUE;
    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);