0

I've an XML/JSON file(a web service response). This response contains nested elements. How can I convert the nested elements into plain elements so that I can use them in my Ad-Hoc Reports. Here is the sample of nested elements.
From the below sample xml I would like to access q1 with an element name as Releases.curryear.Sales.q1 Instead of traversing it. Guide me in solving this.

<book>
<category>reference</category>
<author>Nigel Rees</author>
<title>Sayings of the Century</title>
<price>8.95</price>
<Releases>
    <curryear>
        <Sales>
            <q1>20000</q1>
            <q2>23650</q2>
        </Sales>
    </curryear>
  <prevyear>
        <Sales>
            <q1>23000</q1>
            <q2>23650</q2>
            <q3>24700</q3>
            <q4>25650</q4>
        </Sales>
  </prevyear>
</Releases>

Note: The response contains more than 100 000 records

James Z
  • 12,209
  • 10
  • 24
  • 44
GeekExplorer
  • 260
  • 2
  • 6
  • 23
  • 2
    For java part you can refer http://stackoverflow.com/questions/1823264/quickest-way-to-convert-xml-to-json-in-java – Akhil Jun 08 '16 at 05:05
  • What is a "lac"? How do you traverse? – tobi6 Jun 08 '16 at 05:48
  • @tobi6 its lakh i.e., records can be more than 100,000. I'm not sure about which approach I should follow, that's why posted it here for some guidance. – GeekExplorer Jun 08 '16 at 05:51
  • @Apollo I had gone through the link provided, but none of the solution converts the nested element to a single element as required. Still looking for solution. – GeekExplorer Jun 08 '16 at 05:59
  • 1
    @tobi6 "lakh" is a word in Indian English meaning one hundred thousand. (Note Indian English has more native speakers than British English or American English, so you'd better get used to it...) – Michael Kay Jun 08 '16 at 07:32
  • @MichaelKay It's not about the word, it's about the numbering system -- and there's more people in the world that do not use Indian numbering system -- so with that logic, shouldn't Indians get used to using million etc? – James Z Jun 08 '16 at 14:20

1 Answers1

0

I think that you are searching for something that's called XPath or JSONPath.

Here an example for XPath: how-to-read-xml-using-xpath-in-java

Community
  • 1
  • 1
YKay
  • 131
  • 5