note 93637 added to book.dom
| From: | odessa131 at aol dot nospam dot com | Date: | Sun, 20 Sep 2009 13:49:08 +0000 |
| Subject: | note 93637 added to book.dom | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160866@lists.php.net to get a copy of this message | ||
I had the hardest time updating a complex XML document. Here's a quick example on how to do it.
<?php
// Load the XML from a file.
$xml = "a2062.xml"; // This is an XFDL form previously unencoded and ungzipped.
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->Load($xml);
// Create an XPath query.
// Note: you must define the namespace if the XML document has defined namespaces.
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('xfdl', "http://www.PureEdge.com/XFDL/6.5");
// Locate the value for the first Item Description field.
$query = "//xfdl:page/xfdl:field[@sid='ITEMDESA']/xfdl:value";
$nodeList = $xpath->query($query);
$nodeList->item(0)->nodeValue = "This is the text in the value node of the first Item
Description field inside the DA 2062 PureEdge form.";
$dom->save($xml);
?>
I hope this helps someone.
----
Server IP: 209.41.74.194
Probable Submitter: 214.13.16.115
----
Manual Page -- http://www.php.net/manual/en/book.dom.php
Edit -- https://master.php.net/note/edit/93637
Del: integrated -- https://master.php.net/note/delete/93637/integrated
Del: useless -- https://master.php.net/note/delete/93637/useless
Del: bad code -- https://master.php.net/note/delete/93637/bad+code
Del: spam -- https://master.php.net/note/delete/93637/spam
Del: non-english -- https://master.php.net/note/delete/93637/non-english
Del: in docs -- https://master.php.net/note/delete/93637/in+docs
Del: other reasons-- https://master.php.net/note/delete/93637
Reject -- https://master.php.net/note/reject/93637
Search -- https://master.php.net/manage/user-notes.php