{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • General /
avatar image
0
Question by mohana monangi · Sep 06, 2016 at 12:47 PM · 4.8k Views jsontoxml

JSON to XML Conversion - issue with attributes and Namespaces

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.

Comment
Add comment Show 2
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anil Sagar @ Google ♦♦   · Sep 06, 2016 at 05:08 PM 0
Link

Dear @mohana monangi , Can you please update question with below details to better understand same ?

  • What's the expected SOAP Request ?
  • What's the current SOAP Request you see ?
  • What's the JSON to XML Policy ? , Please post the policy code.
  • What's the JSON request you are sending ?
avatar image mohana monangi · Sep 06, 2016 at 06:10 PM 0
Link

@Anil Sagar

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>


Close

1 Answer

  • Sort: 
avatar image
0
Best Answer

Answer by srinandans@google · Sep 06, 2016 at 05:01 PM

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"
      }
    }
  }
}
Comment
Add comment Show 4 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mohana monangi · Sep 06, 2016 at 06:00 PM 0
Link

@Srinandan Sridhar

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

avatar image srinandans@google ♦ mohana monangi · Sep 06, 2016 at 09:38 PM 0
Link

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>

avatar image mohana monangi srinandans@google ♦ · Sep 07, 2016 at 08:31 PM 0
Link

@Srinandan Sridhar

Thanks Nandan, its working now

Show more comments

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Week5 JSON to XML Error 1 Answer

Using variables to craft XML request from JSON using AssignMessage payload 1 Answer

JsonToXml Policy Help: Why does ObjectRootElementName only get outputted when a JSON array is provided? 1 Answer

JSONtoXML policy suggesting "_" as default for InvalidCharsReplacement? 1 Answer

JSON to XML Policy: Re-sequence XML nodes based on Schema 2 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges