1

Backend system accepts the request in xml format and returns a complex response xml.
Request Xml and Response Xml is generic and has multiple layers. Xml elements do not have one to one mapping with UI fields. Xml contains a lot of metadata(id etc) and layers.
This is the reason I came up with Model xmls which are flat and have one to one mapping with UI fields.
I have following approaches to render data on UI:

  1. UI -> JSON ->ModelXml -> Request Xml/ In case of Response XML, reverse flow
    a. JSON -> ModelXML transformation using some api
    b. ModelXML -> RequestXml using XSLT

  2. UI -> JSON ->RequestXML/ In case of Response XML, reverse flow
    This will be one to one mapping and whenever there is a change on the UI, someone needs to take care of JSON->RequestXML transformation.

Note: UI layout is configurable. Here I am talking 200+ data entry forms.

So the question which one is a better approach in terms for less development time, performance and maintainability?

Is it possible to do JSON <-> XML with XSLT? For example:

**Xml Structure**
<RequestXml>
 <Paramateres>
   <Metadata></Metadata>
 </Paramateres>
 <Party>
  <State></State>
  <Person>
    <FirstName></FirstName>
    <LastName></LastName>
  </Person>
  <Address type="Residence">
    <Line1>28 North Main Street</Line1>
    <City>Alberta</City>
  </Address>
  <SSN></SSN>
 </Party>
</RequestXml>

JSON

"ClientInformation":{"FirstName":"Name", "LastName":"Yadav","Line1":"28 North Main Street","City":"Alberta","State":"", "SSN":""}
Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291

2 Answers2

0

Yes, you can convert between JSON and XML using XSLT. There are a number of resources out there to do this. One you might want to take a look at is XSLTJSON. It lets you perform the conversion according to a number of different conventions. It sounds like your context is a heavily used UI (you mention 200+ data entry forms), so whether this type of conversion is performant enough for your situation is something you need to consider.

BitMask777
  • 2,543
  • 26
  • 36
0

Have you looked at using the json library (http://www.json.org/javadoc/org/json/XML.html)? You can use that to convert back and forth between well formatted XML and JSON directly.
(due to rep, have to break this into two posts - so see comment below for continuation)

John
  • 376
  • 1
  • 7
  • Or if you want to use pojo backed objects, you can serialize and deserialize objects from JSON to Object, Object to XML, XML to Object, and Object to JSON. This is usually the approach I take if I have to accept JSON or XML, work with the data, and then send out differing result types to the UI or file. Typically I use ObjectMapper (http://jackson.codehaus.org/) for handling the JSON and XStream (http://xstream.codehaus.org/) for the XML. – John Nov 08 '13 at 20:56
  • Please take a look at my comment on the question. Yes I have checked these options. – Himanshu Yadav Nov 08 '13 at 23:00
  • 1
    My apologies. I did miss your comment. It's really up to you which is better for your needs. In most of the projects I've worked on, the two options I opted for are much easier for maintainability. For performance, it really depends on how you handle the conversions, the size of the XML messages, etc... Many times for larger files, XSLT has been faster for me than converting to/from different formats; however, the differences in performance (in most of the cases I can think of off-hand) did not outweigh the ease of maintainability. – John Nov 13 '13 at 18:50