[SR-Users] xmlops/xpath access of multiple nodes

Alex Balashov abalashov at evaristesys.com
Mon Jan 30 15:28:50 CET 2012


Hi,

I guess this is more of an xpath question than a Kamailio one, so 
forgive me.  All the same, how does one deal with a document like this 
using $xml(...):

    <?xml version="1.0" encoding="utf-8" ?>
    <sheep>
      <lamb>
         ...
      </lamb>
      <lamb>
         ...
      </lamb>
    </sheep>

Specifically, how do I access the second, third, Nth element with the 
same tag, but without knowledge of any unique identifying attributes? 
  Is there a useful way to iterate through them in Kamailio route script?

I would have thought something like this could work:

    $var(i) = 0;

    while(defined $xml(x=>xpath:/sheep/lamb[$var(i)])) {
       ...
       $var(i) = $var(i) + 1;
    }

However, obviously, that's not it.  So what's the right way to do it?

My desire is to buffer data from these nodes into an AVP array.  As 
you might guess, it's a route set over which I need to serially fork.

Thanks!

-- Alex

-- 
Alex Balashov - Principal
Evariste Systems LLC
260 Peachtree Street NW
Suite 2200
Atlanta, GA 30303
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/, http://www.alexbalashov.com/



More information about the sr-users mailing list