How to parse xml tag in POST body

Hi,

My POST request to F5 looks like this:

<ScheduleRecordings>

<ShowingID>REC_4344</ShowingID>

<Channel>4344</Channel>

</ScheduleRecordings>

How do I parse the Channel header value.

Gil

Hi

This is more a kind of regex question, I guess, but this should do the trick :

regexp {<Channel>(.*)</Channel>} [HTTP::payload] → CHANNEL

Didn’t get time to test it though :slight_smile:

Let me know

Should it put the value in CHANNEL?

If I print CHANNEL it says no such variable.

I’m getting “1”

log local0. [regexp {<Channel>(.*)</Channel>} [HTTP::payload] → CHANNEL]

To be sure which variable gets the payload try

regexp {<Channel>(.*)</Channel>} [HTTP::payload] VAR1 VAR2 VAR3

And print all variables in LTM logs.

And, forgot to escape / maybe :slight_smile:

<Channel>(.*)<\/Channel>

Escaping isn’t needed.

Anyway, with this:

log local0. [regexp {<Channel>(.*)</Channel>} [HTTP::payload] VAR1 VAR2 VAR3]

I’m getting result “1” no matter what tag i’m looking.

How do I print all the VARs?

log local0. “$VAR1 $VAR2”

After the regexp line

Yoann

ok, cool. got it!!

btw, I understand that regexp is CPU intensive, is there any better option to go?

Indeed, be careful with regex :slight_smile:

But to achieve parsing in an XML payload, no choice really. Other approach would be to post in the payload something simpler to parse/split/cut… with string operations

ShowingID=REC_4344&Channel=4344

But if you must have XML, then no choice really

ok thanks.

btw, is there a better way to do it than this:

regexp {<Channel>(.*)</Channel>} [HTTP::payload] VAR1 VAR2

set CHANNEL “$VAR2”

regexp {<Channel>(.*)</Channel>} [HTTP::payload] match CHANNEL

Like this you can use $CHANNEL immédiately.

log local0. “$CHANNEL”

Should show you the value.

Do not hesitate to mark this Answered :slight_smile: