tuananh / camaro

camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
MIT License
556 stars 29 forks source link

Question - Nested Template #129

Closed dhammikabo closed 2 years ago

dhammikabo commented 2 years ago

I am looking to build a template for the following XML where the nesting can have many levels (i.e. Number of sub folders levels is not known)

<root>
  <file name="welcome.txt"/>
  <folder name="Fruits" >
       <file  name= "apple"/>
       <file name = "banana"/>
  </folder>
  <folder name="Vehicles">
     <folder name ="JPVehicles">
          <file name ="Toyota"/>
          <file name = "Mazda">
     </folder>
     <folder name ="NAVehicles"/>
          <file name ="Ford"/>
          <file name="GMC"/>
     </folder>
  </folder>
</root>

With an expected json of:


[
  {
    "type": "file",
    "title": "welcome.txt",
    "path": "/"
  },
  {
    "type": "folder",
    "title": "fruits",
    "path": "/fruits",
    "children": [
      {
        "type": "file",
        "title": "apple",
        "path": "/fruits/apple"
      },
      {
        "type": "file",
        "title": "banana",
        "path": "/fruits/banana"
      }
    ]
  },
  {
    "type": "folder",
    "title": "Vehicles",
    "path": "/Vehicles",
    "children": [
      {
        "type": "folder",
        "title": "JPVehicles",
        "path": "/Vechiles/JPVehicles",
        "children": [
          {
            "type": "file",
            "title": "toyota",
            "path": "/Vehicles/JPVehicles/toyota"
          },
          {
            "type": "file",
            "title": "mazda",
            "path": "/Vehicles/JPVehicles/mazda"
          }
        ]
      }
    ]
  },
  {
    "type": "folder",
    "title": "NAVehicles",
    "path": "/Vechiles/NAVehicles",
    "children": [
      {
        "type": "file",
        "title": "ford",
        "path": "/Vehicles/NAVehicles/Ford"
      },
      {
        "type": "file",
        "title": "GMC",
        "path": "/Vehicles/NAVehicles/GMC"
      }
    ]
  }
]

Can someone help me define what the template needs to be like ?

tuananh commented 2 years ago

@dhammikabo it's not supported at the moment for use cases like this

dhammikabo commented 2 years ago

thanks for getting back to me.