Forum Discussion
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
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 :)
- Yoann_Le_Corvi1
Cumulonimbus
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 :-)
Let me know
- mrgilchen
Altostratus
Should it put the value in CHANNEL?
If I print CHANNEL it says no such variable.
- mrgilchen
Altostratus
I'm getting "1"
log local0. [regexp {<Channel>(.*)</Channel>} [HTTP::payload] -> CHANNEL]
- Yoann_Le_Corvi1
Cumulonimbus
To be sure which variable gets the payload try
regexp {<Channel>(.*)</Channel>} [HTTP::payload] VAR1 VAR2 VAR3
And print all variables in LTM logs.
- Yoann_Le_Corvi1
Cumulonimbus
And, forgot to escape / maybe :)
<Channel>(.*)<\/Channel>
- mrgilchen
Altostratus
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?
- Yoann_Le_Corvi1
Cumulonimbus
log local0. "$VAR1 $VAR2"
After the regexp line
Yoann
- mrgilchen
Altostratus
ok, cool. got it!!
btw, I understand that regexp is CPU intensive, is there any better option to go?
- Yoann_Le_Corvi1
Cumulonimbus
Indeed, be careful with regex :)
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
- mrgilchen
Altostratus
ok thanks.
btw, is there a better way to do it than this:
regexp {<Channel>(.*)</Channel>} [HTTP::payload] VAR1 VAR2
set CHANNEL "$VAR2"
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com