Traversing the Tree

XML trees are very inter-linked documents. There are functions for getting children (like xmlTreeGetChildren()), getting various siblings (xmlTreeGetNext()), and the parent (xmlTreeGetParent()).

Attributes exist outside of the normal hierarchy. You can get all (or specific) attributes with xmlTreeGetAttributes(), or you can begin iterating over them with xmlTreeGetFirstAttribute().

Namespaces also exist outside of the normal hierarchy. See the Using Namespaces (here) section for more information.


<rootNode><name>John Doe</name><age>34</age></rootNode>
</capture><$xmlRaw = $ret>
<$doc = (xmlTreeNewDocFromString($xmlRaw))>
<$root = (xmlTreeGetRootElement($doc))>
<$name = (xmlTreeGetChildren($root, 'name'))>
<$nameText = (xmlTreeGetContent($name))>
<$age = (xmlTreeGetNext($name))>
<$ageText = (xmlTreeGetContent($age))>
name is $nameText, age is $ageText

xmlTreeGetDoc, xmlTreeGetRootElement, xmlTreeGetChildren, xmlTreeGetFirstChild, xmlTreeGetNext, xmlTreeGetPrevious, xmlTreeGetParent, xmlTreeGetFirstAttribute, xmlTreeGetAttributes, xmlTreeGetNs, xmlTreeGetNsDef, xmlTreeLookupNsPrefix, xmlTreeLookupNsURI

Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.