vADC Forum

Posts: 29
Registered: ‎10-19-2013
Accepted Solution

iterate through XML Elements (or convert to array)


does anybody know a easy way to iterate through xml-elements within trafficscript?

my xml (-part) looks like this:




<string>this is the title</string>






<string>this is the description</string>



and i want to iterate through the "member"-sections... It would be great if there is a xml-toarray or xml-tohash function.


Posts: 44
Registered: ‎04-15-2014

Re: iterate through XML Elements (or convert to array)

Hi Jochen,

Use the following code snippet to get the response. Note that I wrapped your xml example to a root element to avoid xml parsing errors.

$count = xml.xpath.matchNodeCount($body,"","//root/member");

$response = "There are " . $count . " members\n";

for( $i=1; $i <= $count; $i++ ) {

   $query = "//root/member[" . $i. "]/name/text()";

    $name = xml.xpath.matchNodeSet($body,"",$query );

   $query = "//root/member[" . $i . "]/value/string/text()";

    $value = xml.xpath.matchNodeSet($body,"",$query );

   $response .= "  " . $name . ": " . $value . "\n";




Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.