xmlnode
The [xmlnode] is used to retrieve the contents of the specific node, where as [xmlnodes] is used to list all nodes within a path.
Parameters
Parameter | Description |
---|---|
ref | Reference to an xml object variable. If this parameter is not provided, then it is assumed that there is an 'outer' [xmlnode] or [xmlnodes] context from which to reference a particular XML node. |
var | User defined name for this persisted node instance. If this parameter is not provided, then this node instance will not be persisted |
path | Path to the desired XML node. If an XPath expression is used, it should evaluate to a single node. |
Tags available within a [xmlnode] context:
Tag | Description |
---|---|
name | The name of the XML node. |
value | The value of the XML node. Will be empty if the node is a 'container' node, i.e. contains other XML nodes. |
content | The 'raw' XML content of the node. |
iscontainer | 'T' if the current node contains other XML nodes. |
The 'path' parameter is used to locate the node. As with the [xmlnodes] context, the 'path' parameter has three modes; named, indexed, and xpath.
[xmlnode] can also be used to persist a 'pointer' to a specific node. This reference can then be used in subsequent calls to other XML contexts.
From example-file.xml the [xmlnode] context can be used to retrieve the TITLE information of the third CD node.
Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml
TITLE=Greatest Hits
If the XML has been parsed previously on the page then there is no need to parse it again if performing subsequent operations on the same XML data. In the example below the var 'xml_var1' is referenced as previously parsed XML data. Using [xmlnode] to get all of the XML data within the node, the XML data within that node can be accessed using [xmlnodes].
Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml
TITLE = Greatest Hits
ARTIST = Dolly Parton
COUNTRY = USA
COMPANY = RCA
PRICE = 9.90
YEAR = 1982
[xmlnode] can also be used to persist a 'pointer' to a specific node. This reference can then be used in subsequent calls to other XML contexts.
From example-file.xml the [xmlnode] context can be used to retrieve the TITLE information of the third CD node.
Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml
[xmlparse var=xml_var1][include file=example-file.xml][/xmlparse]
[xmlnode ref=xml_var1&path=indexed:1/3/1]
[name] = [value]
[/xmlnode]
Results: Note that that the indexed path method is used. This assumes that the desired XML node is already known. TITLE=Greatest Hits
If the XML has been parsed previously on the page then there is no need to parse it again if performing subsequent operations on the same XML data. In the example below the var 'xml_var1' is referenced as previously parsed XML data. Using [xmlnode] to get all of the XML data within the node, the XML data within that node can be accessed using [xmlnodes].
Example WebDNA code:
This example uses an example file that you can view/download here example-file.xml
[xmlnode ref=xml_var1&path=indexed:1/3&var=xml_CD3][/xmlnode]
[xmlnodes ref=xml_CD3]
[name] = [value]
[/xmlnodes]
Results: The content of the 3rd node is stored in memory by WebDNA with the reference 'xml_CD3', this reference is then used to get the content of the referenced node.TITLE = Greatest Hits
ARTIST = Dolly Parton
COUNTRY = USA
COMPANY = RCA
PRICE = 9.90
YEAR = 1982