|
This section discusses some of the details of the structure of the
trees created when parsing an XML document with the xmlTree
interface and how to use them.
The samples/xmlapi directory contains the following code examples:
-
xmlTree01_New - shows many ways of creating new
nodes in an XML tree -
xmlTree02_Get - shows ways of extracting information from
an XML document -
xmlTree03_Sibling - shows many of the tree traversal
mechanisms -
xmlTree04_Ns - shows how to resolve and examine namespace
information in a tree -
xmlTree05_SetNs - shows how to create and set namespace
information in a tree -
xmlTree06_Copy - shows how to make copies of nodes in an
XML tree -
xmlTree07_Encoding - shows how to use various
input/output encodings -
xmlTree08_XPath - shows how to use XPath expressions -
xmlTree09_DTD - shows how to extract DTD information -
xmlTree10_XSL - shows how to apply an XSL stylesheet
Below is a small example program that shows how the xmlTree API
can be used to open an XML document, add content to an element, add
another element, and print the output.
<capture>
<Result>
<Url>http://www.example.com/page.htm</Url>
<ResultTitle>Generic Page Title</ResultTitle>
</Result>
</capture><$xmlRaw=$ret>
<$doc = (xmlTreeNewDocFromString($xmlRaw, 'XML_PARSE_NOBLANKS'))>
<$root = (xmlTreeGetRootElement($doc))>
<$title = (xmlTreeGetChildren($root, 'ResultTitle'))>
<$titleText = (xmlTreeGetContent($title))>
Existing title is "$titleText"
<$ret = (xmlTreeAddContent($title, ", now with 12% more fun"))>
<$ret = (xmlTreeNewElement($root, 'Abstract', 'content content'))>
<$output = (xmlTreePrintDoc($doc, 'INDENT'))>
after changes doc is:
$output
Copyright © Thunderstone Software Last updated: Mon Feb 18 10:28:15 EST 2013
|