Forum Discussion

Drewmart's avatar
Drewmart
New Contributor
14 years ago

JSON to XML with no namespaces

When SoapUI converts a JSON message to XML for XPath searching, is there a way to disable namespaces in the XML?

For example, I end up with an XML message like:
<Response xmlns="http://localhost/my/path/here/">

But if I generate tests based on this XML they have this namespace hard-coded. Then, if I run the tests on another server (e.g. 192.168.101.101) the namespace is different and the assertion will fail. If I didn't have to worry about namespaces in the first place, this would be a non-issue. Is there any way to turn it off (so that it ends up looking like <Response>)?
  • stmurphy's avatar
    stmurphy
    New Contributor
    I found that you can use a wild card for the namespace. So if you want to do the following:


    //books/book[1]/title


    Use the following syntax:


    //*:books/*:book[1]/*:title


    This works for me on non-Pro v4.5.1.
  • oysteigi's avatar
    oysteigi
    Occasional Contributor
    I agree that this is very unpractical behaviour, and would like to get that fixed. Especially having the hostname in there is useless. I don't think there is an option to disable the namespace at the moment. I tried to remove the line which adds the namespace, and that does the trick! See the attached patch.

    Unfortunately changing the default behaviour breaks all existing assertions using the current namespace. I tried to figure out when the namespace was put in there, and found this commit:

    r1504 | dain.nilsson | 2009-04-09 12:34:08 +0200 (to., 09 april 2009) | 1 line
    Fixed some REST-related bugs.

    There is no reference to which bugs have been fixed, so I'll drop Dain a line and see if he remembers.

    A safe way to go is to add a configurable option to disable namespaces for JSON responses.
  • Hi,

    This was a while back, so I'm not sure I can remember the exact reason for this, but I do believe it has to do with matching the response type internally in soapUI. Without it, all JSON requests converted to XML look the same, and soapUI doesn't know which schema to validate against (mainly when using schema inferrence). As you suggested, adding an option to specify a namespace instead of basing it off the hostname might be the solution. It's in our backlog of issues to fix. A workaround which works for now is to use a Property Expansion in the XPath match for providing the namespace. The same Property could be used for specifying the endpoint.

    Regards,
    Dain
    SmartBear Sweden
  • Any updates on being able to disable the namespace?

    I want to do an assertion on "//response/node1/node2" but without the response because the namespace changes.

    I'd rather just go straight to "exists(/node1/node2)" and not worry about the namespace at all.
  • leskop's avatar
    leskop
    Occasional Contributor
    You can use following in XPath Match:


    /*[local-name() = 'Response']//*[local-name() = 'testKey1']//*[local-name() = 'someValueHere']//*[local-name() = 'dataKey1']/text()


    Hope it helps
  • Any progress on this issue? This is a major issue for us.....

    The world is moving more and more in the direction of REST-Full APIs with JSON.

    Can we not have a button (similar to "Declare") that would transform from:

    declare namespace ns1='http://localhost/my/path/here/';
    exists(//ns1:Response/ns1:node1/ns:node2)

    to:

    exists(//*[local-name() = 'Response']/*[local-name() = 'node1']/*[local-name() = 'node1'])