I have a SOAP webservice for which I consume in a flow service. The output from the connector is a complex document representation of the XML response.
At present, seamless conversion between xml and json is not possible. Therefore, if the document type has the name in the format - prefix:name, the same is assigned as key in JSON.
You may have to modify/cleanup the document names via custom code before you can send it to documentToJSONString service. I know you mentioned this is not preferable, but that is the only way it would work as per your requirements as of now.
Thanks for providing the clarification. I seem to get similar feedback from other folks as well.
What intrigues me is, how is the webMethods API Gateway automatically doing the same conversion without actually showing the namespaces.
I am almost certain they are not using String replacement. Therefore I assume there would be some approach(eventhough it involves code).
I checked with the team, they seem to be using custom code to convert XML to JSON using jettison libraries. They also claim that namespace prefixes are not removed…I am not sure of that behavior though.
(The abomination that is XML namespaces continues to deliver challenges )
It used to be possible to set namespaces such that the prefix was empty for a given namespace – a default namespace. But since the move from Developer to Designer, Designer forces a prefix, though I have managed to work-around it. Alas, I don’t recall exactly how.
The ability to do so is definitely present – when you receive an XML doc the sender uses the prefixes they want. They can be anything at all, including nothing. IS XML parsing understands how to translate what the sender sends to the defined prefixes you want/need – including nothing (default namespace).
Although this post does not give the specifics of how because I’ve long forgotten, I thought I’d share that you should be able to do this. The key is defining a document type where the field names do not have prefixes, but are defined with a namespace.
Be aware of the corner cases where XML to JSON has challenges. Single element arrays, attribute naming, complex elements to name a few. All can be addressed but need specific attention/approach
I don’t think this is accurate. I cannot be certain as the screen shot does not show the full namespace declarations. But “pricePart” is either not in a namespace, and would have no prefix, or is in a default namespace, and would have no prefix. “hy” is not the namespace, it is the namespace prefix. I note this to emphasize that there are multiple ways that an element within a namespace can be represented. The lack of a prefix does not mean the namespace is removed.
For the purposes here, it is the namespace prefix that is undesirable. The key here is telling the xmlNodeToDocument service to change the prefix of a given namespace from whatever it is in the document the sender provided to be the prefix you want – which is nothing. The challenge as noted above is how to get the “nothing” defined in Designer – it really wants a var to have a name. I managed to do so some time ago. Here is a screen shot:
The trick is using the “Set a Value” button for the document and then “Add Row” for each namespace. For each namespace, use a literal space for the var name and paste the namespace as the value. Use 1 space for the first namespace, 2 spaces for the next, and so on. This is because they need to be uniquely named.
Downside of this approach is you need to know all the namespaces (not the prefixes) ahead of time. And the funky setting of the nsDecls var. If you’re adventurous you could probably use queryXMLNode to get a list of the namespaces that are present in a given document, then dynamically create the nsDecls var so you wouldn’t need to know the namespaces ahead of time.
However I do have a followup situation which if you could assist would be great.
While invoking a soap connector, the XML/SOAP output would be in the form of a document. Therefore I would have to invoke the documentToXMLString and then repeat the steps
Question : Do you foresee any scalability issues with this approach?
Question : Is there a better approach?
It certainly adds a reparse and additional memory usage. Whether or not that would be an issue depends on the size of the documents and how often the service is called.