Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Opinions on parsing XML to JSON design

  • 10-03-2013 06:16PM
    #1
    Closed Accounts Posts: 6,075 ✭✭✭


    Can any give their opinions on my design?

    Write Java web service to:
    • Call external web service that returns an XML document as a String of 'Car' information.
    • Search this xml/string object for particular Car (bring me back all Fords).
    • Return all Fords as a JSON object.

    Solution:
    • Call external web service to get an XML file (as string) of all Car information.
    • Using JAXB, parse this String object into multiple Car objects.
    • Loop through the car objects and when I find a Ford, add it to a Car list.
    • Loop through Ford list and convert the list into a JSON object.
    • Return JSON object from web service.

    I need my solution to demonstrate good coding practices, not just get a working solution.

    What do you think?


Comments

  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Can any give their opinions on my design?

    Write Java web service to:
    • Call external web service that returns an XML document as a String of 'Car' information.
    • Search this xml/string object for particular Car (bring me back all Fords).
    • Return all Fords as a JSON object.

    Solution:
    • Call external web service to get an XML file (as string) of all Car information.
    • Using JAXB, parse this String object into multiple Car objects.
    • Loop through the car objects and when I find a Ford, add it to a Car list.
    • Loop through Ford list and convert the list into a JSON object.
    • Return JSON object from web service.

    I need my solution to demonstrate good coding practices, not just get a working solution.

    What do you think?

    Your Car Information XML document can be searched using XPath expressions. This would be better than parsing into multiple car objects and iterating through.

    The Xpath expression should return the car(s) elements and from there you can convert into JSON objects.


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    Use Google's gson lib for your marshaling of json.


Advertisement