Hi,
I'm having troubles fetching an xpath from an xml document using presence_xml, so I probably do something wrong (using kamailio 3.0.x):
$xml(x=>doc) = '<?xml version="1.0" encoding="utf-8"?><presence xmlns="urn:ietf:params:xml:ns:pidf" entity="sip:test@mydomain.com"><tuple id="86ae65b7-42de-4399-b635-295caad13aac"><status><basic>none</basic></status></tuple></presence>';
xlog("L_INFO", "all=$xml(x=>doc)\n");
-> prints the whole document, which is ok
xlog("L_INFO", "tmp1=$xml(x=>xpath:/)\n");
-> also prints the whole document (including the xml tag in the beginning, not sure if this is ok)
xlog("L_INFO", "tmp2=$xml(x=>xpath:/presence)\n");
-> prints an empty string
How is this actually supposed to work? What I'd like to do in the end is extracting for example the "none" from the "basic"-tag by specifying "xpath:/presence/tuple/status/basic", which also returns an empty string now, also when appended with "/text()".
Thanks a lot, Andreas
Hello,
On 12/6/10 3:13 PM, Andreas Granig wrote:
Hi,
I'm having troubles fetching an xpath from an xml document using presence_xml, so I probably do something wrong (using kamailio 3.0.x):
$xml(x=>doc) = '<?xml version="1.0" encoding="utf-8"?><presence xmlns="urn:ietf:params:xml:ns:pidf" entity="sip:test@mydomain.com"><tuple id="86ae65b7-42de-4399-b635-295caad13aac"><status><basic>none</basic></status></tuple></presence>';
xlog("L_INFO", "all=$xml(x=>doc)\n");
-> prints the whole document, which is ok
xlog("L_INFO", "tmp1=$xml(x=>xpath:/)\n");
-> also prints the whole document (including the xml tag in the beginning, not sure if this is ok)
xlog("L_INFO", "tmp2=$xml(x=>xpath:/presence)\n");
-> prints an empty string
How is this actually supposed to work? What I'd like to do in the end is extracting for example the "none" from the "basic"-tag by specifying "xpath:/presence/tuple/status/basic", which also returns an empty string now, also when appended with "/text()".
the problem is in between IETF and XML guys :-)
xpath require to use a prefix for namespaces. The SIMPLE guys liked to set a default one without prefix.
For this case, try:
modparam("presence_xml", "xml_ns", "pidf=urn:ietf:params:xml:ns:pidf")
then:
xlog("L_INFO", "tmp2=$xml(x=>xpath:/pidf:presence/pidf:tuple/pidf:status/pidf:basic)\n");
- see which one is giving more convenient resultL with text() or no text()
There are some tricks I did for the xcap_server, because I think this is not scaling. There I just changed 'xmlns=' in 'xmlnx=' or so, so there is no namespace without prefix -- then your format for xpath works fine.
Cheers, Daniel
Hi Daniel,
How is this actually supposed to work? What I'd like to do in the end is extracting for example the "none" from the "basic"-tag by specifying "xpath:/presence/tuple/status/basic", which also returns an empty string now, also when appended with "/text()".
the problem is in between IETF and XML guys :-)
xpath require to use a prefix for namespaces. The SIMPLE guys liked to set a default one without prefix.
For this case, try:
modparam("presence_xml", "xml_ns", "pidf=urn:ietf:params:xml:ns:pidf")
then:
xlog("L_INFO", "tmp2=$xml(x=>xpath:/pidf:presence/pidf:tuple/pidf:status/pidf:basic)\n");
Got it. But what if it gets a bit more difficult than that? :)
I've an xml document where the namespace for some elements changes, like this:
<?xml version="1.0" encoding="utf-8"?> <presence xmlns="urn:ietf:params:xml:ns:pidf" entity="sip:foo@mydomain.com"> <tuple id="86ae65b7-42de-4399-b635-295caad13aac"> <status> <basic>none</basic> <geopriv xmlns="urn:ietf:params:xml:ns:pidf:geopriv10"> <location-info> <location xmlns="http://www.opengis.net/gml"> [snip]
As you can see, the "geopriv" element changes the namespace from "pidf" to "pidf:geopriv10". Even giving the full namespace (".../urn:ietf:params:xml:ns:pidf:geopriv10:geopriv") to capture the "geopriv" element results in
ERROR: presence_xml [pv_xml.c:310]: unable to evaluate xpath expression [/pidf:presence/pidf:tuple/pidf:status/urn:ietf:params:xml:ns:pidf:geopriv10:geopriv/83]
Any ideas are highly appreciated :)
Andreas
Hello,
On 12/6/10 6:09 PM, Andreas Granig wrote:
Hi Daniel,
How is this actually supposed to work? What I'd like to do in the end is extracting for example the "none" from the "basic"-tag by specifying "xpath:/presence/tuple/status/basic", which also returns an empty string now, also when appended with "/text()".
the problem is in between IETF and XML guys :-)
xpath require to use a prefix for namespaces. The SIMPLE guys liked to set a default one without prefix.
For this case, try:
modparam("presence_xml", "xml_ns", "pidf=urn:ietf:params:xml:ns:pidf")
then:
xlog("L_INFO", "tmp2=$xml(x=>xpath:/pidf:presence/pidf:tuple/pidf:status/pidf:basic)\n");
Got it. But what if it gets a bit more difficult than that? :)
I've an xml document where the namespace for some elements changes, like this:
<?xml version="1.0" encoding="utf-8"?>
<presence xmlns="urn:ietf:params:xml:ns:pidf" entity="sip:foo@mydomain.com">
<tuple id="86ae65b7-42de-4399-b635-295caad13aac"> <status> <basic>none</basic> <geopriv xmlns="urn:ietf:params:xml:ns:pidf:geopriv10"> <location-info> <location xmlns="http://www.opengis.net/gml"> [snip]
As you can see, the "geopriv" element changes the namespace from "pidf" to "pidf:geopriv10". Even giving the full namespace (".../urn:ietf:params:xml:ns:pidf:geopriv10:geopriv") to capture the "geopriv" element results in
ERROR: presence_xml [pv_xml.c:310]: unable to evaluate xpath expression [/pidf:presence/pidf:tuple/pidf:status/urn:ietf:params:xml:ns:pidf:geopriv10:geopriv/83]
Any ideas are highly appreciated :)
you can define many xml_ns parameters, each with different prefix. I guess the inner xmlns overwrites the other one in your sample xml document, so you have to use different prefix for that nodes:
modparam("presence_xml", "xml_ns", "pidf=urn:ietf:params:xml:ns:pidf") modparam("presence_xml", "xml_ns", "geop=urn:ietf:params:xml:ns:pidf:geopriv10")
Try a path like: /pidf:presence/pidf:tuple/pidf:status/geop:geopriv/...
Hope it works.
Daniel
On 12/06/2010 07:17 PM, Daniel-Constantin Mierla wrote:
you can define many xml_ns parameters, each with different prefix. I guess the inner xmlns overwrites the other one in your sample xml document, so you have to use different prefix for that nodes:
modparam("presence_xml", "xml_ns", "pidf=urn:ietf:params:xml:ns:pidf") modparam("presence_xml", "xml_ns", "geop=urn:ietf:params:xml:ns:pidf:geopriv10")
Try a path like: /pidf:presence/pidf:tuple/pidf:status/geop:geopriv/...
Works like charm, thanks a lot :)
Andreas