LibXML doesn't find any nodes for my xpath expression - iphone

I'm using xpath and LibXML in an iPhone app to find some nodes in an xml document. I'm a noob in xpath so probably i am doing something wrong.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetUserByEmailResponse xmlns="http://tempuri.org/">
<GetUserByEmailResult>
<id>4006</id>
<name>Kudor Gyozo</name>
<email/>
<image/>
<facebookId>0</facebookId>
</GetUserByEmailResult>
</GetUserByEmailResponse>
</soap:Body>
</soap:Envelope>
The xpath expression is //GetUserByEmailResult. No nodes are returned. I expect to get <GetUserByEmailResult> back. If I test the same stuff here it works ok.
UPDATE1: This is what i get back from a .net web service. Is there a way to ignore namespaces in libxml?

I'm not familiar with the iphone library, but you'll probably have to declare the namsepace / prefix somewhere: If you register 'http://tempuri.org/' with 'someprefix', you can search for:
//someprefix:GetUserByEmailResult
A possible workaround is (but not advisable):
//*[local-name()='GetUserByEmailResult']

The GetUserByEmailResult element is in the http://tempuri.org/ namespace so you would need to add that namespace to your XPath search.
You can do so using the xmlXPathRegisterNs function:
xmlXPathRegisterNs(context, BAD_CAST "temp", BAD_CAST "http://tempuri.org/");
Then your XPath would have to be changed to
//temp:GetUserByEmailResult

Related

Why there are different request definition for one wsdl

I have been provided a WSDL by client at the beginning of the project, I ended up creating a request and response objects for given WSDL using SOAP UI, where the request object would look as follows,
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:def="http://DefaultNamespace">
<soapenv:Header/>
<soapenv:Body>
<def:someOperation soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<in0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">SOME_DATA</in0>
</def:someOperation>
</soapenv:Body>
</soapenv:Envelope>
But when the actual request coming from the production environment for the same wsdl is,
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<someOperation xmlns="urn:SOMEService">
<in0>SOME_DATA</in0>
</someOperation>
</soap:Body>
</soap:Envelope>
If you observed the name spaces are the same but it does has difference for names like in 1st request its <soapenv:Envelope and same in the 2nd request is <soap:Envelope in each node of xml, the definition of operation is also different in both the request in 1st it is,
<def:someOperation soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<in0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">SOME_DATA</in0>
</def:someOperation>
and in 2nd it is,
<someOperation xmlns="urn:SOMEService">
<in0>SOME_DATA</in0>
</someOperation>
I do not know why the interpretation is different, and is it safe to have to change from 1st to 2nd.
IN both the cases actual operation is working fine I do not have any issues with that, it is just cant able to figure out reason of difference.
Could somebody please assist me with this or any direction to a document which could clarify my doubt would be great.
it does has difference for names like in 1st request its <soapenv:Envelope and same in the 2nd request is <soap:Envelope in each node of xml
Here soapenv and soap are local prefix names of namespace=http://schemas.xmlsoap.org/soap/envelope/. Hence, logically both are same and has no difference.
the definition of operation is also different in both the request in 1st v/s 2nd
In case of 1st, def:someOperation XML nodes belongs to namespace = xmlns:def="http://DefaultNamespace"
And in 2nd case, name space "urn:SOMEService" is directly defined with XML Nodes So
if DefaultNamespace is exactly same as SOMEService, the it means both of the XML Operation XMLs are same.
Hence,
soapenv v/s soap are same in your case.
Operations, you could conclude based on actual value of SOMEService v/s DefaultNamespace.
Hope it helps.

Get data from xml response in Jmeter

Hi Everyone!
I would like to get status from this response from Jmeter.How can i create regexp for that?
I just want to get 'vacant' from response
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns5:GetRandomMSISDNListResponse xmlns:ns2="http://www.trump.com/products/common/core" xmlns:ns3="http://www.trump.com/products/common/rr" xmlns:ns4="http://www.yota224.com/vux/domains/common/core" xmlns:ns5="http://www.yota224.com/vux/services/inventory">
<ns2:extension>
<ns2:item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:RequestContextType">
<ns2:correlationId>8f7ce7e1-31ae-40fe-82ba-4d59f634e599</ns2:correlationId>
</ns2:item>
</ns2:extension>
<msisdnList>
<homeRegion>1078</homeRegion>
<msisdn>9992146221</msisdn>
<status>vacant</status>
</msisdnList>
</ns5:GetRandomMSISDNListResponse>
</soap:Body>
</soap:Envelope>
If you targeting to do it via Regular Expressions - the relevant one would be something like:
<status>(\w+)</status>
Here is how it looks in the "RegExp Tester" mode of the View Results Tree listener
Also it might be easier to use XPath Extractor which is designed for working with XML data. In that case the relevant XPath query to get the status will be as simple as:
//status

Parsing XML (SOAP Response) through NetSuite Script

In Netsuite Script I am trying to parse the response from EchoSign Webservice. The response from EchoSign is like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<getFormDataResponse xmlns="http://api.echosign">
<getFormDataResult xmlns="http://api.echosign">
<errorCode xmlns="http://dto8.api.echosign">OK</errorCode>
<errorMessage xmlns="http://dto8.api.echosign" xsi:nil="true" />
<formDataCsv xmlns="http://dto8.api.echosign">SOME DATA </formDataCsv>
<success xmlns="http://dto8.api.echosign">true</success>
</getFormDataResult>
</getFormDataResponse>
</soap:Body>
</soap:Envelope>
And my NetSuite code is here
var response = nlapiRequestURL(echoSignUrl, postStr, header);
var xml = nlapiStringToXML(response.getBody());
var resData = nlapiSelectNode(xml, 'soap:Envelope/soap:Body'); // /getFormDataResult/success');
if (resData)
return nlapiSelectValue(resData, 'formDataCsv');
But somehow I always get nothing back from nlapiSelectValue method!!
Nodes without any prefix should be accessed using default prefix nlapi:
for e.g. /soap:Envelope/soap:Body/nlapi:getFormDataResponse
It appears to be an issue with the way the namespacing is handled. Using the XML Tools plugin for Notepad++ and the XML you've provided, the XPATH Current Node Selector can't even find the getFormDataResponse node correctly. It simply fails with "Unknown Exception".
I also tried to manually evaluate the following expressions:
/soap:Envelope/soap:Body (works)
/soap:Envelope/soap:Body/getFormDataResponse (fails)
/soap:Envelope/soap:Body//getFormDataResponse (fails)
/soap:Envelope/soap:Body/*[local-name() = 'getFormDataResponse'] (fails)
/soap:Envelope/soap:Body/descendants::*[local-name() = 'getFormDataResponse'] (fails)
/soap:Envelope/soap:Body/descendants::getFormDataResponse (fails)
If I modify the XML so the EchoSign namespaces are in the Envelope with a prefix, like so:
<soap:Envelope xmlns:echo="http://api.echosign" xmlns:dto8="http://dto8.api.echosign" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<echo:getFormDataResponse>
<echo:getFormDataResult>
<dto8:errorCode>OK</dto8:errorCode>
<dto8:errorMessage xsi:nil="true" />
<dto8:formDataCsv>SOME DATA</dto8:formDataCsv>
<dto8:success>true</dto8:success>
</echo:getFormDataResult>
</echo:getFormDataResponse>
</soap:Body>
</soap:Envelope>
then the path selector can get all the way down to the formDataCsv node correctly. It returns the path: /soap:Envelope/soap:Body/echo:getFormDataResponse/echo:getFormDataResult/dto8:formDataCsv.
Not sure how helpful that is because you're not in control of the XML that EchoSign sends to you, but I'm not sure how to correctly format the XPATH to deal with the namespaces.

Microsoft Dynamics SOAP RetrieveMultiple not returning TotalRecordCount

I'm working with the SOAP API for Microsoft Dynamics CRM 4.0 and for the most part everything is working, but when I'm trying to count the number of total contacts in the database (or for particular queries), it's not respecting the TotalRecordCount=true flag.
Here is the SOAP request that I'm using:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<CrmAuthenticationToken xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
...
</CrmAuthenticationToken>
</soap:Header>
<soap:Body>
<RetrieveMultiple xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
<query xmlns:q1="http://schemas.microsoft.com/crm/2006/Query" xsi:type="q1:QueryExpression">
<q1:EntityName>contact</q1:EntityName>
<q1:Distinct>true</q1:Distinct>
<q1:PageInfo>
<q1:ReturnTotalRecordCount>true</q1:ReturnTotalRecordCount>
<q1:PageNumber>1</q1:PageNumber>
<q1:Count>1</q1:Count>
</q1:PageInfo>
</query>
</RetrieveMultiple>
</soap:Body>
</soap:Envelope>
But the response that I'm getting back still contains the following:
TotalRecordCount="-1" TotalRecordCountLimitExceeded="0"
Any idea what I'm doing wrong / missing here?
Do you get any results in your query? E.g. do you recieve the contact records?
I'm pretty sure I've had a problem with this type of approach in the past (using the paging information to get a count).
In any case you will probably have better luck with peforming a FetchXml query with an aggregate function (Im assuming your executing this Soap from JavaScript).
Jamie Miley has a good example of how to do this: http://mileyja.blogspot.co.uk/2011/06/aggregation-count-max-min-etc-and.html
There is a really good designer for FetchXml here: http://www.stunnware.com/

Problem using NSXMLParser with NOAA data on iPhone

Can anyone help me see why NSXMLParser is not causing these methods
parser:didStartElement:namespaceURI:qualifiedName:attributes:
parser:didEndElement:namespaceURI:qualifiedName:attributes:
to fire for the part of the following data:
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:NDFDgenResponse xmlns:ns1=""><dwmlOut xsi:type="xsd:string"><?xml version="1.0"?>
<dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.nws.noaa.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
(body excluded)
</dwml>
</dwmlOut></ns1:NDFDgenResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
I'm not an XML expert, but to me, the <dwml></dwml> part looks like just a regular element, to be parsed just like the parts before it.
I do get two parser:parseErrorOccurred: errors, #200 and #201, but they occur during the parsing of the <SOAP-ENV:Body> element, not the <dwml> element, so I'm not sure if they are relevant. Thanks for any help you can give me.
Update: A friend of mine has told me offline of several errors in the data above. I can't understand why NOAA would be sending out malformed XML though -- is there some secret to parsing it?
This is a SOAP web service, you might want to try this: http://code.google.com/p/wsdl2objc/