Xpath cheat sheet https://devhints.io/xpath
&fbclid=IwAR0NMTTKRSXPhzSxQLJlHl-jC7qhvL_ebYD3WVsilXgNW6X08Qj-77s0EnI
ความรู้ เครื่องมือ สำหรับนักพัฒนา
Comment reported successfully.
Post was successfully added to your timeline!
You have reached your limit of 5000 friends!
File size error: The file exceeds allowed the limit (23 MB) and can not be uploaded.
Unable to upload a file: This file type is not supported.
We have detected some adult content on the image you uploaded, therefore we have declined your upload process.
To upload images, videos, and audio files, you have to upgrade to pro member. Upgrade To Pro
TNX TNX
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<parent>
<child nr="1"/>
<child nr="2"/>
</parent>
</root>
<?php
$xml_src = 'test.xml';
// XPath-Querys
$parent_path = "//parent";
$next_path = "//parent/child[@nr='2']";
// Create a new DOM document
$dom = new DomDocument();
$dom->load($xml_src);
// Find the parent node
$xpath = new DomXPath($dom);
// Find parent node
$parent = $xpath->query($parent_path);
// new node will be inserted before this node
$next = $xpath->query($next_path);
// Create the new element
$element = $dom->createElement('newnode';
// Insert the new element
$parent->item(->insertBefore($element, $next->item();
echo $dom->saveXML();
?>
Delete Comment
Are you sure that you want to delete this comment ?