Technical References - [xmlnodes]

The behavior of this context is to iterate the child XML nodes of a parent node.

numero = 282
interpreted = N
texte = [xmlnodes ref=...&path=...&name=...&exact=T/F] <WebDNA>[/xmlnodes] Parameters: · ref - Reference to an xml parsed object variable. If this parameter is not provided, then it is assumed that there is an 'outer' [xmlnodes] context from which to reference a particular XML node. (This is explained further on in this tutorial). · path - Depending on which path method is used (see below), this will either be a path to the parent xml element (node) from which to iterate the child elements (nodes), or a path 'expression' representing a collection of XML nodes. If a path is not provided, then the child nodes of the 'ref' node will be iterated · name - A string used to filter the resulting xml nodes. Only the xml nodes that match the 'name' string will be iterated. · exact - Used with the 'name' parameter. Either 'T' or 'F'. Specifies whether the 'name' parameter is a 'whole' string match or a 'sub-string' match. Context Tags available from within the [xmlnodes] Context: · [name] - The name of the current iterated XML node. · [value] - The value of the current iterated XML node. Will be empty if the node is a 'container' node, i.e. contains other XML nodes. · [index] - The 'count' of the current iterated node. · [numfound] - The total 'count' of iterated nodes. · [content] - The 'raw' xml content of the current node. · [iscontainer] - 'T' if the current node contains other XML nodes. The default behavior of this context is to iterate the child XML nodes of a parent node. The location of the parent node, in the xml 'tree', is determined by the 'path' parameter. If a path parameter is not provided, then the child nodes of the ' ref 's root are iterated. The path parameter can take three different forms: 'named:', 'indexed:', or 'xpath:'. - The 'named:' method expresses a literal path to the parent node, i.e. 'path=named:CATALOG/CD(n)'. If there are more than one similarly named 'sibling' nodes, then the '(n)' part specifies which node to select as part of the path. - The 'indexed:' method expresses an numerical 'step' wise path to the parent node, i.e. 'path=indexed:1/2/3'. This example could be expressed as: 'The third child node of the second child node of the first child node of the xml root'. - The 'xpath:' method is an XPath 'expression' that evaluates to a collection of nodes in the XML tree. In this case, the iterated nodes are those of the resulting 'collection' of nodes. This is a bit different from the 'named' and 'indexed' method in that the collection of node are not the 'child' nodes of a given 'parent' node. This is the most powerful method for selecting XML nodes. There are several online 'xpath' tutorials that you can visit that will help you develop your XPath skills. We will be using the 'named' method later in this tutorial page. Now lets use the [xmlnodes] context to iterate the xml child nodes of the root xml node of the 'example1.xml' document. The code is as follows...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse][xmlnodes ref=xml_var1][name]=[value][/xmlnodes]
Results.... CATALOG= We see that the 'CATALOG' node is the only child node from the root of the xml file. Notice that the 'value' is empty. This is because the 'CATALOG' node has no value, and is actually a 'container' node for other xml nodes. So a 'value' will only be displayed for a 'leaf' xml node, i.e. JOHN In this case, [name] would evaluate to 'FIRSTNAME' and [value] would be 'JOHN'. Lets dive a little deeper into the xml file and iterate the 'child' nodes of the root 'catalog' node of the example1.xml file... We now use...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse][xmlnodes ref=xml_var1&path=named:Catalog][name]=[value][/xmlnodes]
Results.... CD= CD= CD= CD= CD= We see that we have iterated all the 'CD' child nodes of the 'Catalog' parent node. Again, none of the resulting child nodes contain a value as they are all 'container' nodes. You can embed any number of [xmlnodes] contexts within each other. Lets do this to iterate the child nodes of all the 'CD' nodes of the example1.xml file... We use...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse][xmlnodes ref=xml_var1&path=named:Catalog][name] - [index][xmlnodes]- [name]=[value][/xmlnodes][/xmlnodes]
Results.... CD - 1 - TITLE=Empire Burlesque - ARTIST=Bob Dylan - COUNTRY=USA - COMPANY=Columbia - PRICE=10.90 - YEAR=1985 CD - 2 - TITLE=Hide your heart - ARTIST=Bonnie Tylor - COUNTRY=UK - COMPANY=CBS Records - PRICE=9.90 - YEAR=1988 CD - 3 - TITLE=Greatest Hits - ARTIST=Dolly Parton - COUNTRY=USA - COMPANY=RCA - PRICE=9.90 - YEAR=1982 CD - 4 - TITLE=Still got the blues - ARTIST=Gary More - COUNTRY=UK - COMPANY=Virgin records - PRICE=10.20 - YEAR=1990 Now we are getting some interesting results. Note that the 'inner' xmlnodes context did not need a 'ref' parameter. This is because the inner xmlnodes context inherited the outer xmlnodes' current iterated node. Also notice that the inner xmlnodes context did not use a 'path' parameter. So it uses the 'root' path of the outer xmlnodes' current iterated node. Did you also notice the use of the [index] tag in the outer xmlnodes context? As with most 'iterative' WebDNA contexts, the [index] tag resolves to the current iteration 'count'. Lets refine the named path parameter to go directly to a particular 'CD' node. With a minor change to the 'path' parameter, we can retrieve all the child nodes of the fifth 'CD' node of the example1.xml file...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse][xmlnodes ref=xml_var1&path=named:Catalog/CD(5)][name]=[value][/xmlnodes]
Results.... TITLE=Eros ARTIST=Eros Ramazzotti COUNTRY=EU COMPANY=BMG PRICE=9.90 YEAR=1997 Using the 'name' parameter we can filter the results to display only the 'TITLE' node of the fifth 'CD' node of the example1.xml file...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse][xmlnodes ref=xml_var1&path=named:Catalog/CD(5)&name=TITLE][name]=[value][/xmlnodes]
Results.... TITLE=Eros Using the 'name' and 'exact' parameters, we can filter the results to display only those nodes, of the fifth 'CD' node, where the node name matches a given sub-string, 'CO' of the example1.xml file...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse][xmlnodes ref=xml_var1&path=named:Catalog/CD(5)&name=CO&exact=F][name]=[value][/xmlnodes]
Results.... COUNTRY=EU COMPANY=BMG Lets move on to the [xmlnode] context... [xmlnodes ref=...&path=...&name=...&exact=T/F] <WebDNA>[/xmlnodes]

Parameters:

· ref - Reference to an xml parsed object variable. If this parameter is not provided, then it is assumed that there is an 'outer' [xmlnodes] context from which to reference a particular XML node. (This is explained further on in this tutorial).

· path - Depending on which path method is used (see below), this will either be a path to the parent xml element (node) from which to iterate the child elements (nodes), or a path 'expression' representing a collection of XML nodes. If a path is not provided, then the child nodes of the 'ref' node will be iterated

· name - A string used to filter the resulting xml nodes. Only the xml nodes that match the 'name' string will be iterated.

· exact - Used with the 'name' parameter. Either 'T' or 'F'. Specifies whether the 'name' parameter is a 'whole' string match or a 'sub-string' match.

Context Tags available from within the [xmlnodes] Context:

· [name] - The name of the current iterated XML node.

· [value] - The value of the current iterated XML node. Will be empty if the node is a 'container' node, i.e. contains other XML nodes.

· [index] - The 'count' of the current iterated node.

· [numfound] - The total 'count' of iterated nodes.

· [content] - The 'raw' xml content of the current node.

· [iscontainer] - 'T' if the current node contains other XML nodes.

The default behavior of this context is to iterate the child XML nodes of a parent node. The location of the parent node, in the xml 'tree', is determined by the 'path' parameter. If a path parameter is not provided, then the child nodes of the ' ref 's root are iterated.

The path parameter can take three different forms: 'named:', 'indexed:', or 'xpath:'.

- The 'named:' method expresses a literal path to the parent node, i.e. 'path=named:CATALOG/CD(n)'. If there are more than one similarly named 'sibling' nodes, then the '(n)' part specifies which node to select as part of the path.

- The 'indexed:' method expresses an numerical 'step' wise path to the parent node, i.e. 'path=indexed:1/2/3'. This example could be expressed as: 'The third child node of the second child node of the first child node of the xml root'.

- The 'xpath:' method is an XPath 'expression' that evaluates to a collection of nodes in the XML tree. In this case, the iterated nodes are those of the resulting 'collection' of nodes. This is a bit different from the 'named' and 'indexed' method in that the collection of node are not the 'child' nodes of a given 'parent' node. This is the most powerful method for selecting XML nodes. There are several online 'xpath' tutorials that you can visit that will help you develop your XPath skills.

We will be using the 'named' method later in this tutorial page.

Now lets use the [xmlnodes] context to iterate the xml child nodes of the root xml node of the 'example1.xml' document.

The code is as follows...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse]
[xmlnodes ref=xml_var1]
[name]=[value]
[/xmlnodes]

Results....

CATALOG=

We see that the 'CATALOG' node is the only child node from the root of the xml file. Notice that the 'value' is empty. This is because the 'CATALOG' node has no value, and is actually a 'container' node for other xml nodes. So a 'value' will only be displayed for a 'leaf' xml node, i.e.

JOHN

In this case, [name] would evaluate to 'FIRSTNAME' and [value] would be 'JOHN'.

Lets dive a little deeper into the xml file and iterate the 'child' nodes of the root 'catalog' node of the example1.xml file...

We now use...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse]
[xmlnodes ref=xml_var1&path=named:Catalog]
[name]=[value]
[/xmlnodes]

Results....

CD=
CD=
CD=
CD=
CD=

We see that we have iterated all the 'CD' child nodes of the 'Catalog' parent node. Again, none of the resulting child nodes contain a value as they are all 'container' nodes.

You can embed any number of [xmlnodes] contexts within each other. Lets do this to iterate the child nodes of all the 'CD' nodes of the example1.xml file...

We use...
[xmlparse var=xml_var1][include file=example1.xml][/xmlparse]
[xmlnodes ref=xml_var1&path=named:Catalog]
[name] - [index]
[xmlnodes]
- [name]=[value]
[/xmlnodes]
[/xmlnodes]

Results....

CD - 1
- TITLE=Empire Burlesque
- ARTIST=Bob Dylan
- COUNTRY=USA
- COMPANY=Columbia
- PRICE=10.90
- YEAR=1985
CD - 2
- TITLE=Hide your heart
- ARTIST=Bonnie Tylor
- COUNTRY=UK
- COMPANY=CBS Records
- PRICE=9.90
- YEAR=1988
CD - 3
- TITLE=Greatest Hits
- ARTIST=Dolly Parton
- COUNTRY=USA
- COMPANY=RCA
- PRICE=9.90
- YEAR=1982
CD - 4
- TITLE=Still got the blues
- ARTIST=Gary More
- COUNTRY=UK
- COMPANY=Virgin records
- PRICE=10.20
- YEAR=1990

Now we are getting some interesting results. Note that the 'inner' xmlnodes context did not need a 'ref' parameter. This is because the inner xmlnodes context inherited the outer xmlnodes' current iterated node. Also notice that the inner xmlnodes context did not use a 'path' parameter. So it uses the 'root' path of the outer xmlnodes' current iterated node.

Did you also notice the use of the [index] tag in the outer xmlnodes context?
As with most 'iterative' WebDNA contexts, the [index] tag resolves to the current iteration 'count'.

Lets refine the named path parameter to go directly to a particular 'CD' node.

With a minor change to the 'path' parameter, we can retrieve all the child nodes of the fifth 'CD' node of the example1.xml file...

[xmlparse var=xml_var1][include file=example1.xml][/xmlparse]
[xmlnodes ref=xml_var1&path=named:Catalog/CD(5)]
[name]=[value]
[/xmlnodes]

Results....

TITLE=Eros
ARTIST=Eros Ramazzotti
COUNTRY=EU
COMPANY=BMG
PRICE=9.90
YEAR=1997

Using the 'name' parameter we can filter the results to display only the 'TITLE' node of the fifth 'CD' node of the example1.xml file...

[xmlparse var=xml_var1][include file=example1.xml][/xmlparse]
[xmlnodes ref=xml_var1&path=named:Catalog/CD(5)&name=TITLE]
[name]=[value]
[/xmlnodes]

Results....

TITLE=Eros

Using the 'name' and 'exact' parameters, we can filter the results to display only those nodes, of the fifth 'CD' node, where the node name matches a given sub-string, 'CO' of the example1.xml file...

[xmlparse var=xml_var1][include file=example1.xml][/xmlparse]
[xmlnodes ref=xml_var1&path=named:Catalog/CD(5)&name=CO&exact=F]
[name]=[value]
[/xmlnodes]


Results....

COUNTRY=EU
COMPANY=BMG

Lets move on to the [xmlnode] context...

DOWNLOAD WEBDNA NOW!

Top Articles:

Download WebDNA Applications

WebDNA applications...

AWS Raw WebDNA LAMP-Plus WebServer

Amazon Web Services (AWS) README for Machine Image ID...

[biotype]

BioType is a behavioral biometrics WebDNA function based on ADGS research and development (from version 8...

WebDNA Modules

A list of the currently available modules...

WebDNA Libraries

A list of available libraries for WebDNA...

Tips and Tricks

A list of user-submitted tips ...

Related Readings:

[clearlineitems]

Remove all line items from the specified shopping cart...

[listwords]

Breaks a string of text into separate words...

[authenticate]

WebDNA provides a few options for password protecting your pages...

[protect]

...

[movefile]

This instructions move a file from one location to another...

[format]

To apply formats for Dates or Times other than the current date and time...