Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOAP request fails #34

Open
tosbaha opened this issue Apr 11, 2015 · 5 comments
Open

SOAP request fails #34

tosbaha opened this issue Apr 11, 2015 · 5 comments

Comments

@tosbaha
Copy link

tosbaha commented Apr 11, 2015

For the following XML document(SOAP service), XPath can't find the elements.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <ServiceResponse xmlns="http://sub.domain.com">
            <ServiceReturn>
                <a>US</a>
                <b>
                    <b>
                        <e>Herrod</e>
                        <f>molestie@necmetus.edu</f>
                        <g>Et Commodo LLC</g>
                        <i>07/14/2014</i>
                    </b>
                    <b>
                        <e>Armand</e>
                        <f>est@vitae.org</f>
                        <g>Vel Convallis In Consulting</g>
                        <i>04/18/2015</i>
                    </b>
                    <b>
                        <e>Bernard</e>
                        <f>nulla@blandit.net</f>
                        <g>Cursus Nunc Mauris PC</g>
                        <i>11/12/2015</i>
                    </b>
                    <b>
                        <e>Dante</e>
                        <f>lorem@acmi.org</f>
                        <g>Sit Amet Ltd</g>
                        <i>01/19/2016</i>
                    </b>
                </b>
                <c>0</c>
                <k>12345678</k>
            </ServiceReturn>
        </ServiceResponse>
    </soapenv:Body>
</soapenv:Envelope>

Here are the result of some functions

document.rootElement.firstChildWithTag("Body", inNamespace: "soapenv") //some
document.rootElement.firstChildWithTag("//soapenv:Body/ServiceResponse") //nil
document.rootElement.firstChildWithTag("//Body//b", inNamespace: "soapenv") //nil
document.firstChildWithXPath("//ServiceResponse") //nil
document.firstChildWithXPath("//ServiceReturn") //nil
document.firstChildWithXPath("//*/ServiceReturn/b/b") //nil
document.firstChildWithXPath("//ServiceReturn/b/b") //nil
document.firstChildWithXPath("//b/b") //nil

Another example

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:OperationHistoryData xmlns:ns2="http://www.domain.org/operation" xmlns:ns3="http://www.domain.org/info" xmlns:ns5="http://www.domain.org/data">
         <ns2:historyRecord>
            <ns2:DestinationAddress>
               <ns2:Index>190000</ns2:Index>
               <ns2:Description>Info 1</ns2:Description>
            </ns2:DestinationAddress>
         </ns2:historyRecord>
      </ns2:OperationHistoryData>
   </S:Body>
</S:Envelope>

Whenever there is nested namespaces, ono can't parse it. I don't know maybe it is limitation of libxml. Only workaround I found is to strip name spaces and other attributes.

@ghost
Copy link

ghost commented Apr 13, 2015

I have the same problem and have to go down the elements until I get to the element I want:

ONOXMLElement *dataElement = [[[[[[[[[document.rootElement.children firstObject] children] firstObject] children] firstObject] children] firstObject] children] firstObject];

Here are some details about the problem:

"The ‘gotcha’ moment with our response message is that the namespace “xmlns=http://ws.cdyne.com/WeatherWS/” does not have a prefix for the declaration. By not defining a prefix, it is defaulting to the default namespace or null namespace and we cannot use XPath expressions to reference the null namespace."

http://blog.inin.com/a-quick-primer-on-soap-xml-and-xpath/

@cHaLkdusT
Copy link

cHaLkdusT commented Mar 29, 2017

Hi @mattt,

What is the status of this issue? It seems like I'm experiencing it too.

Regards,
Chalk

@mattt
Copy link
Owner

mattt commented Mar 21, 2018

Apologies for not responding sooner, everyone. I'm not very familiar with SOAP, but I'd like to make any necessary fixes for this in code and/or documentation. I'll add the example you provided, @tosbaha, as a failing test case in a branch and work to figure out a solution.

"The ‘gotcha’ moment with our response message is that the namespace “xmlns=http://ws.cdyne.com/WeatherWS/” does not have a prefix for the declaration. By not defining a prefix, it is defaulting to the default namespace or null namespace and we cannot use XPath expressions to reference the null namespace."

In the meantime, have you tried calling the definePrefix:forDefaultNamespace as a workaround?

@tosbaha
Copy link
Author

tosbaha commented Mar 21, 2018

Sorry but this issue was so old. I don't work on this anymore. I think I made it work by stripping the name spaces. Since I don't have the old code anymore, I can't comment whether your workaround works or not. Cheers.

@cHaLkdusT
Copy link

I've tested this by calling definePrefix:forDefaultNamespace, however, XPath queries still returns nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants