-->

Parsing a xml file and convert into a JSON file us

2019-09-16 13:12发布

问题:

I want to convert xml file into my specific JSON format

Example :

<Bank>
    <Account>
        <Id1>1001</Id1>
        <Name1>Sony Corporation</Name1>
        <Amt1>1000000</Amt1>
        <age>23</age>
    </Account>
    <Account>
        <Id2>1002</Id2>
        <Name2>Sony Corporation</Name2>
        <Amt2>1000000</Amt2>
    </Account>
</Bank>

Now JSON format :

  1. For JSON format I want to identify which tag has child element and which tag has not? If it has child then I have to start one object into that object column name and start array.

example :

    { 
        "Bank":[
  1. I want to identify end tag also i.e. in our case Account,Bank end tag? for that I want to close array and object

example:

     }
  ]
  1. For element which has no childs.

example:

 {
    "column name":"Id",
    "column value":"1001"
 }
  1. For element which has no childs we have maxCount.

Example:

If maxCount is 3 then only first three childs should be written into JSON.

Please give me hints for completing this task... thanks in advance...