We need to call the SOAP direct update call and the soap message contains attributes and name spaces. While constructing the SOAP message from REST message, we are facing issue. The SOAP message contains attributes like below and the index keep on increasing. SOAP message: <input z:Id="i1" i:type="Person" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <Addresses> <Address z:Id="i2"> <City>NLanarkshorth ire</City> <Country>.</Country> <County>.</County> <ID>123456</ID> <IsDefault>true</IsDefault> <ItemValidMethod>Unspecified</ItemValidMethod> <Line1> St</Line1> <Line2>well</Line2> </Address> </Addresses> <CreatedDate>2016-08-12T21:20:25.437</CreatedDate> <Emails> <Email z:Id="i3"> <Address>123@gmail.com</Address> <ID>12434</ID> <IsDefault>true</IsDefault> <PartyID>123</PartyID> <Purpose>Employment</Purpose> </Email> </Emails> I tried as per below REST to SOAP conversion suggested by Apigee, getting error due to z:Id . "Addresses":{ "Address":{ "#attrs":{ "@z:Id":"i2" },
Error getting like unspecified attribute _z. Please help.
Solved! Go to Solution.
I didn't find any problem converting that XML to JSON (using default settings)
<input z:Id="i1" i:type="Person" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <Addresses> <Address z:Id="i2"> <City>NLanarkshorth ire</City> <Country>.</Country> <County>.</County> <ID>123456</ID> <IsDefault>true</IsDefault> <ItemValidMethod>Unspecified</ItemValidMethod> <Line1> St</Line1> <Line2>well</Line2> </Address> </Addresses> <CreatedDate>2016-08-12T21:20:25.437</CreatedDate> <Emails> <Email z:Id="i3"> <Address>123@gmail.com</Address> <ID>12434</ID> <IsDefault>true</IsDefault> <PartyID>123</PartyID> <Purpose>Employment</Purpose> </Email> </Emails> </input>
Output:
{ "input": { "@xmlns": { "i": "http://www.w3.org/2001/XMLSchema-instance", "z": "http://schemas.microsoft.com/2003/10/Serialization/" }, "@z:Id": "i1", "@i:type": "Person", "Addresses": { "Address": { "@z:Id": "i2", "City": "NLanarkshorth\nire", "Country": ".", "County": ".", "ID": 123456, "IsDefault": true, "ItemValidMethod": "Unspecified", "Line1": " St", "Line2": "well" } }, "CreatedDate": "2016-08-12T21:20:25.437", "Emails": { "Email": { "@z:Id": "i3", "Address": "123@gmail.com", "ID": 12434, "IsDefault": true, "PartyID": 123, "Purpose": "Employment" } } } }
I didn't find any problem converting that XML to JSON (using default settings)
<input z:Id="i1" i:type="Person" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <Addresses> <Address z:Id="i2"> <City>NLanarkshorth ire</City> <Country>.</Country> <County>.</County> <ID>123456</ID> <IsDefault>true</IsDefault> <ItemValidMethod>Unspecified</ItemValidMethod> <Line1> St</Line1> <Line2>well</Line2> </Address> </Addresses> <CreatedDate>2016-08-12T21:20:25.437</CreatedDate> <Emails> <Email z:Id="i3"> <Address>123@gmail.com</Address> <ID>12434</ID> <IsDefault>true</IsDefault> <PartyID>123</PartyID> <Purpose>Employment</Purpose> </Email> </Emails> </input>
Output:
{ "input": { "@xmlns": { "i": "http://www.w3.org/2001/XMLSchema-instance", "z": "http://schemas.microsoft.com/2003/10/Serialization/" }, "@z:Id": "i1", "@i:type": "Person", "Addresses": { "Address": { "@z:Id": "i2", "City": "NLanarkshorth\nire", "Country": ".", "County": ".", "ID": 123456, "IsDefault": true, "ItemValidMethod": "Unspecified", "Line1": " St", "Line2": "well" } }, "CreatedDate": "2016-08-12T21:20:25.437", "Emails": { "Email": { "@z:Id": "i3", "Address": "123@gmail.com", "ID": 12434, "IsDefault": true, "PartyID": 123, "Purpose": "Employment" } } } }
My issue is JSON to XML, If I convert the above JSON message into XML(SOAP request), I am missing the attributes.
"@z:Id":"i1", -- giving problem
I got this XML
<?xml version="1.0" encoding="UTF-8"?> <input xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i1" i:type="Person"> <Addresses> <Address z:Id="i2"> <City>NLanarkshorth ire</City> <Country>.</Country> <County>.</County> <ID>123456</ID> <IsDefault>true</IsDefault> <ItemValidMethod>Unspecified</ItemValidMethod> <Line1> St</Line1> <Line2>well</Line2> </Address> </Addresses> <CreatedDate>2016-08-12T21:20:25.437</CreatedDate> <Emails> <Email z:Id="i3"> <Address>123@gmail.com</Address> <ID>12434</ID> <IsDefault>true</IsDefault> <PartyID>123</PartyID> <Purpose>Employment</Purpose> </Email> </Emails> </input>
The attributes seem to be there.
Here is my policy XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <JSONToXML async="false" continueOnError="false" enabled="true" name="json-to-xml"> <DisplayName>JSON to XML</DisplayName> <Properties/> <Options> <NullValue>NULL</NullValue> <NamespaceBlockName>@xmlns</NamespaceBlockName> <DefaultNamespaceNodeName>$</DefaultNamespaceNodeName> <NamespaceSeparator>:</NamespaceSeparator> <TextNodeName>TEXT</TextNodeName> <AttributePrefix>@</AttributePrefix> <InvalidCharsReplacement>_</InvalidCharsReplacement> <ArrayItemElementName>Item</ArrayItemElementName> </Options> <OutputVariable>response</OutputVariable> <Source>response</Source> </JSONToXML>
hi mohana monangi ,
how do you have your xml attribute in json?
<Address z:Id="i2">
i have this problem
<amount Code="MXN">20.0</amount>
i try many json but all is wrong.
Thanks.
Regards
Dear @mohana monangi , Can you please update question with below details to better understand same ?
JSON Message I am posting:
{ "Addresses":{ "Address":{ "#attrs":{ "@Id":"i2" }, "City":"hoboken", "Country":".", "County":".", "ID":"12344", "IsDefault":"true", "ItemValidMethod":"Unspecified", "Line1":"Hoboke St", "Line2":"Motherwell", "PartyID":"123456", "Postcode":"ML1 3AQ", "Purpose":"MainHome" } }, "CreatedDate":"2016-08-12T21:20:25.437", "Emails":{ "Email":{ "#attrs":{ "@Id":"i3" }, "Address":"123@gmail.com", "ID":"1234", "IsDefault":"true", "PartyID":"123456", "Purpose":"Employment" } } } Below is expected SOAP request: <Addresses> <Address z:Id="i2"> <City>hoboken</City> <Country>.</Country> <County>.</County> <ID>12344</ID> <IsDefault>true</IsDefault> <ItemValidMethod>Unspecified</ItemValidMethod> <Line1>Hoboke St</Line1> <Line2>Motherwell</Line2> <PartyID>123456</PartyID> <Postcode>ML1 3AQ</Postcode> <Purpose>MainHome</Purpose> </Address> </Addresses> <CreatedDate>2016-08-12T21:20:25.437</CreatedDate> <Emails> <Email z:Id="i3"> <Address>123@gmail.com</Address> <ID>1234</ID> <IsDefault>true</IsDefault> <PartyID>123456</PartyID> <Purpose>Employment</Purpose> </Email> </Emails> Below is the JSON to XML Policy Code(default)" <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <JSONToXML async="false" continueOnError="false" enabled="true" name="JSON-to-XML-1"> <DisplayName>JSON to XML-1</DisplayName> <Properties/> <Options> <NullValue>NULL</NullValue> <NamespaceBlockName>#namespaces</NamespaceBlockName> <DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName> <NamespaceSeparator>:</NamespaceSeparator> <TextNodeName>#text</TextNodeName> <AttributeBlockName>#attrs</AttributeBlockName> <AttributePrefix>@</AttributePrefix> <InvalidCharsReplacement>_</InvalidCharsReplacement> <ObjectRootElementName>Root</ObjectRootElementName> <ArrayRootElementName>Array</ArrayRootElementName> <ArrayItemElementName>Item</ArrayItemElementName> </Options> <OutputVariable>xmlrequest</OutputVariable> <Source>request</Source> </JSONToXML>
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |