Get xpath results

1,945 views
Skip to first unread message

Gert Jan Schipper

unread,
Dec 12, 2012, 10:09:10 AM12/12/12
to gat...@googlegroups.com
This is my response:

<SOAP:Body>
<constructor language="DBSQL">
<query>SELECT BRANCH_ID FROM XDS_BRANCH WHERE NAME = 'CWS-TEST8'</query>
</constructor>
<tuple>
<old>
<XDS_BRANCH>
<BRANCH_ID>ABCF1256781</BRANCH_ID>
</XDS_BRANCH>
</old>
</tuple>
</dataset>
</QueryAdminDataResponse>
</SOAP:Body>

Now I want to save the BRANCH_ID. This is my code:

exec(http("getBranchId")
.post("/home/system/com.eibus.web.soap.Gateway.wcp")
.basicAuth("gschippe", "Cordys123")
.fileBody("getBranchId", Map("workspace" -> "CWS-TEST8")).asXML
.check(xpath("//Body/QueryAdminDataResponse/dataset/tuple/old/XDS_BRANCH/BRANCH_ID[@id='text1']/@value").saveAs("branchID"))

But this doesn't work. What is wrong here?

Stéphane Landelle

unread,
Dec 12, 2012, 10:18:45 AM12/12/12
to gat...@googlegroups.com
Why do you have this [@id='text1']/@value thing?

"/Body/QueryAdminDataResponse/dataset/tuple/old/XDS_BRANCH/BRANCH_ID" should be fine, right?

If you're going with xpath, you should also have a look at the vtd-xml extension whose memory footprint should be much better:


2012/12/12 Gert Jan Schipper <gjschi...@gmail.com>
XDS_BRANCH

Nicolas Rémond

unread,
Dec 12, 2012, 10:21:52 AM12/12/12
to gat...@googlegroups.com
Also, I'm wondering about the "//Body" part as the first tag is "<SOAP:Body>"

Gert Jan Schipper

unread,
Dec 13, 2012, 7:53:47 AM12/13/12
to gat...@googlegroups.com
Yes, "/Body/QueryAdminDataResponse/dataset/tuple/old/XDS_BRANCH/BRANCH_ID" should be fine but it's not working.

Cannot resolve namespace prefix 'SOAP'

Op woensdag 12 december 2012 16:18:45 UTC+1 schreef Stéphane Landelle het volgende:

Stéphane Landelle

unread,
Dec 13, 2012, 9:42:50 AM12/13/12
to gat...@googlegroups.com
First of all, I think your response body , as you wrote it, is invalid: you should have a SOAP:Envelope root.

Let say your body is:

<?xml version="1.0"?>
<SOAP:Envelope xmlns:SOAP="http://www.w3.org/2001/12/soap-envelope/">
<SOAP:Body>
<QueryAdminDataResponse xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
<constructor language="DBSQL">
<query>SELECT BRANCH_ID FROM XDS_BRANCH WHERE NAME = 'CWS-TEST8'
</query>
</constructor>
<tuple>
<old>
<XDS_BRANCH>
<BRANCH_ID>ABCF1256781</BRANCH_ID>
</XDS_BRANCH>
</old>
</tuple>
</dataset>
</QueryAdminDataResponse>
</SOAP:Body>
</SOAP:Envelope>

First, as you would do with any XPath engine, you have to bind the namespaces used in your expression. In Gatling, you do it this way:

Note that starting from QueryAdminDataResponse, you use a default namespace, so you have to bind it too!

If you want to use the whole path starting from root, you can write:
xpath("/SOAP:Envelope/SOAP:Body/monitoring:QueryAdminDataResponse/monitoring:dataset/monitoring:tuple/monitoring:old/monitoring:XDS_BRANCH/monitoring:BRANCH_ID", List("SOAP" -> "http://www.w3.org/2001/12/soap-envelope/", "monitoring" -> "http://schemas.cordys.com/bpm/monitoring/1.0"))

Otherwise, you can use a simplified one:
xpath("//monitoring:BRANCH_ID", List("http://schemas.cordys.com/bpm/monitoring/1.0"))

Then, please note that you're actually performing an "exists" (default) check, so you're saving a boolean. What you want is find or findAll depending on your needs:

Cheers,

Stéphane

2012/12/13 Gert Jan Schipper <gjschi...@gmail.com>

Amuthan G

unread,
Feb 14, 2013, 1:12:36 AM2/14/13
to gat...@googlegroups.com
Dear Landelle,

if my response is something like following

 <InsertEntityInstancesResponse xmlns="http://schemas.test.com/entityserver/runtime/1.0" >
            <Customer id="1314" package="com/test/domain" version="0">
                <id>1314</id>
                <name>HR</name>
                <age>32</age>
                <dateOfBirth>1978-09-21T00:00:00+02:00</dateOfBirth>
                <isGoldCustomer>true</isGoldCustomer>
                <expenditure>1234.567</expenditure>
            </Customer>
        </InsertEntityInstancesResponse>

and if I wanto to fetch name element how can i do that? you should notice that xmlns does not have any prefix

Regards
Amuthan

Amuthan G

unread,
Feb 14, 2013, 5:03:05 AM2/14/13
to gat...@googlegroups.com
any insight on this...

Regards
Amuthan

Stéphane Landelle

unread,
Feb 14, 2013, 6:10:07 AM2/14/13
to gat...@googlegroups.com
Just like with most xpath engines (Gatling uses jaxen, see http://jaxen.codehaus.org/faq.html), you have to declare the namespace.

xpath(//pre:name, List("pre" -> "http://schemas.test.com/entityserver/runtime/1.0"))

Cheers,

Stéphane


2013/2/14 Amuthan G <amu...@cordys.com>

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Amuthan G

unread,
Feb 14, 2013, 6:43:04 AM2/14/13
to gat...@googlegroups.com
thanks it is working
Regards
Amuthan
--

Kind Regards
Amuthan G
Software Engineer
amu...@cordys.com
www.cordys.com
T 040-66561982 • M +91 7799697766

Cordys - The Enterprise Cloud Platform

Reply all
Reply to author
Forward
0 new messages