5.13.1 • Published 4 months ago

gatsby-transformer-xml v5.13.1

Weekly downloads
452
License
MIT
Repository
github
Last release
4 months ago

gatsby-transformer-xml

Parses XML files. It also supports attributes

Install

npm install gatsby-transformer-xml

How to use

// In your gatsby-config.js
plugins: [`gatsby-transformer-xml`]

Parsing algorithm

The algorithm for arrays is to convert each item in the array into a node.

So if your project has a books.xml with

<?xml version="1.0"?>
<catalog>
  <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies,
      an evil sorceress, and her own childhood to become queen
      of the world.</description>
   </book>
</catalog>

The plugin uses xml-parser to convert it to json

{
  "declaration": {
    "attributes": {
      "version": "1.0"
    }
  },
  "root": {
    "name": "catalog",
    "attributes": {},
    "children": [
      {
        "name": "book",
        "attributes": {
          "id": "bk101"
        },
        "children": [
          {
            "name": "author",
            "attributes": {},
            "children": [],
            "content": "Gambardella, Matthew"
          },
          {
            "name": "title",
            "attributes": {},
            "children": [],
            "content": "XML Developer's Guide"
          },
          {
            "name": "genre",
            "attributes": {},
            "children": [],
            "content": "Computer"
          },
          {
            "name": "price",
            "attributes": {},
            "children": [],
            "content": "44.95"
          },
          {
            "name": "publish_date",
            "attributes": {},
            "children": [],
            "content": "2000-10-01"
          },
          {
            "name": "description",
            "attributes": {},
            "children": [],
            "content": "An in-depth look at creating applications\n      with XML."
          }
        ],
        "content": ""
      },
      {
        "name": "book",
        "attributes": {
          "id": "bk102"
        },
        "children": [
          {
            "name": "author",
            "attributes": {},
            "children": [],
            "content": "Ralls, Kim"
          },
          {
            "name": "title",
            "attributes": {},
            "children": [],
            "content": "Midnight Rain"
          },
          {
            "name": "genre",
            "attributes": {},
            "children": [],
            "content": "Fantasy"
          },
          {
            "name": "price",
            "attributes": {},
            "children": [],
            "content": "5.95"
          },
          {
            "name": "publish_date",
            "attributes": {},
            "children": [],
            "content": "2000-12-16"
          },
          {
            "name": "description",
            "attributes": {},
            "children": [],
            "content": "A former architect battles corporate zombies,\n      an evil sorceress, and her own childhood to become queen\n      of the world."
          }
        ],
        "content": ""
      }
    ],
    "content": ""
  }
}

Which then is used to create the nodes.

How to query

You'd be able to query your books like:

{
  allBooksXml {
    edges {
      node {
        name
        xmlChildren {
          name
          content
        }
      }
    }
  }
}

Which would return:

{
  "data": {
    "allBooksXml": {
      "edges": [
        {
          "node": {
            "name": "book",
            "xmlChildren": [
              {
                "name": "author",
                "content": "Gambardella, Matthew"
              },
              {
                "name": "title",
                "content": "XML Developer's Guide"
              },
              {
                "name": "genre",
                "content": "Computer"
              },
              {
                "name": "price",
                "content": "44.95"
              },
              {
                "name": "publish_date",
                "content": "2000-10-01"
              },
              {
                "name": "description",
                "content": "An in-depth look at creating applications\n      with XML."
              }
            ]
          }
        },
        {
          "node": {
            "name": "book",
            "xmlChildren": [
              {
                "name": "author",
                "content": "Ralls, Kim"
              },
              {
                "name": "title",
                "content": "Midnight Rain"
              },
              {
                "name": "genre",
                "content": "Fantasy"
              },
              {
                "name": "price",
                "content": "5.95"
              },
              {
                "name": "publish_date",
                "content": "2000-12-16"
              },
              {
                "name": "description",
                "content": "A former architect battles corporate zombies,\n      an evil sorceress, and her own childhood to become queen\n      of the world."
              }
            ]
          }
        }
      ]
    }
  }
}

Note that the root element "catalog" is ignored, and nodes are created with the children elements.

5.14.0-next.2

4 months ago

5.13.1

4 months ago

5.14.0-next.1

4 months ago

5.13.0

5 months ago

5.14.0-next.0

5 months ago

5.12.0

9 months ago

5.13.0-next.0

10 months ago

5.11.0-next.0

12 months ago

5.11.0-next.1

11 months ago

5.10.0

12 months ago

5.11.0

11 months ago

5.12.0-next.0

11 months ago

5.10.0-next.2

1 year ago

5.10.0-next.1

1 year ago

5.10.0-next.0

1 year ago

5.9.0

1 year ago

5.8.0-next.0

1 year ago

5.8.0

1 year ago

5.9.0-next.0

1 year ago

5.7.0

1 year ago

5.4.0

1 year ago

5.6.0-next.0

1 year ago

5.5.0

1 year ago

5.7.0-next.0

1 year ago

5.6.0

1 year ago

4.25.0

1 year ago

5.1.0-next.0

2 years ago

5.0.0

2 years ago

5.5.0-next.0

1 year ago

5.1.0

1 year ago

5.2.0

1 year ago

5.3.0-next.0

1 year ago

5.3.0

1 year ago

5.0.0-next.1

2 years ago

5.0.0-next.2

2 years ago

5.0.0-next.0

2 years ago

5.0.0-next.3

2 years ago

5.2.0-next.0

1 year ago

3.15.0

1 year ago

5.4.0-next.0

1 year ago

5.4.0-next.1

1 year ago

4.24.0

2 years ago

4.24.0-next.0

2 years ago

4.23.0-next.0

2 years ago

4.23.0

2 years ago

4.22.0

2 years ago

4.25.0-next.0

2 years ago

4.21.0-next.0

2 years ago

4.18.0-next.1

2 years ago

4.18.0-next.0

2 years ago

4.16.0

2 years ago

4.16.0-next.0

2 years ago

4.22.0-next.0

2 years ago

4.19.0-next.1

2 years ago

4.19.0-next.0

2 years ago

4.15.0

2 years ago

4.18.0

2 years ago

4.21.0

2 years ago

4.17.0-next.0

2 years ago

4.17.0

2 years ago

4.20.0

2 years ago

4.20.0-next.0

2 years ago

4.19.0

2 years ago

4.15.0-next.0

2 years ago

4.14.0

2 years ago

4.13.0

2 years ago

4.14.0-next.1

2 years ago

4.14.0-next.2

2 years ago

4.14.0-next.0

2 years ago

4.12.0-next.0

2 years ago

4.11.0-next.0

2 years ago

4.10.0

2 years ago

4.13.0-next.0

2 years ago

4.12.0

2 years ago

4.12.1

2 years ago

4.11.0

2 years ago

4.9.0

2 years ago

4.10.0-next.0

2 years ago

4.10.0-next.1

2 years ago

4.6.0-next.0

2 years ago

4.8.0

2 years ago

4.7.0

2 years ago

4.7.0-next.0

2 years ago

4.6.0

2 years ago

4.5.0-next.0

2 years ago

4.5.0

2 years ago

4.4.0

2 years ago

4.8.0-next.0

2 years ago

4.3.0

2 years ago

4.9.0-next.0

2 years ago

4.4.0-next.0

2 years ago

4.3.0-next.0

2 years ago

4.2.0

2 years ago

4.2.0-next.0

3 years ago

4.1.0

3 years ago

4.0.0

3 years ago

4.1.0-next.0

3 years ago

4.0.0-zz-next.2

3 years ago

3.14.0

3 years ago

4.0.0-zz-next.1

3 years ago

4.0.0-zz-next.8

3 years ago

4.0.0-next.1

3 years ago

4.0.0-next.0

3 years ago

3.14.0-next.2

3 years ago

3.14.0-next.1

3 years ago

3.13.0

3 years ago

3.14.0-next.0

3 years ago

3.12.0

3 years ago

3.13.0-next.0

3 years ago

3.12.0-next.3

3 years ago

3.12.0-next.2

3 years ago

3.12.0-next.1

3 years ago

3.11.0

3 years ago

3.12.0-next.0

3 years ago

3.10.0

3 years ago

3.11.0-next.0

3 years ago

3.10.0-next.1

3 years ago

3.9.0

3 years ago

3.10.0-next.0

3 years ago

3.8.0

3 years ago

3.9.0-next.0

3 years ago

3.8.0-next.0

3 years ago

3.8.0-next.1

3 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.7.0-next.2

3 years ago

3.7.0-next.1

3 years ago

3.6.0

3 years ago

3.5.0-next.0

3 years ago

3.7.0-next.0

3 years ago

3.6.0-next.0

3 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.4.0-next.0

3 years ago

3.3.0-next.1

3 years ago

3.2.0

3 years ago

3.3.0-next.0

3 years ago

3.1.0

3 years ago

3.2.0-next.0

3 years ago

3.1.0-next.2

3 years ago

3.0.0

3 years ago

3.1.0-next.1

3 years ago

3.1.0-next.0

3 years ago

3.0.0-v3rc.0

3 years ago

3.0.0-next.0

3 years ago

2.10.0

3 years ago

2.11.0-next.0

3 years ago

2.9.0

3 years ago

2.10.0-next.0

3 years ago

2.8.0

3 years ago

2.9.0-next.0

3 years ago

2.7.0

3 years ago

2.8.0-next.0

3 years ago

2.6.0

3 years ago

2.7.0-next.0

3 years ago

2.5.0

3 years ago

2.6.0-next.0

3 years ago

2.4.0

3 years ago

2.4.0-next.1

3 years ago

2.5.0-next.0

3 years ago

2.4.0-next.0

4 years ago

2.3.15

4 years ago

2.3.14

4 years ago

2.3.13

4 years ago

2.3.12

4 years ago

2.3.11

4 years ago

2.3.10

4 years ago

2.3.9

4 years ago

2.3.8

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.26

4 years ago

2.1.25

4 years ago

2.1.24

4 years ago

2.1.23

4 years ago

2.1.22

4 years ago

2.1.20

4 years ago

2.1.19

4 years ago

2.1.18

4 years ago

2.1.17

5 years ago

2.1.16

5 years ago

2.1.15

5 years ago

2.1.14

5 years ago

2.1.13

5 years ago

2.1.12

5 years ago

2.1.10

5 years ago

2.1.9

5 years ago

2.1.8

5 years ago

2.1.7

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-rc.6

6 years ago

2.0.0-rc.2

6 years ago

2.0.0-rc.1

6 years ago

2.0.0-rc.0

6 years ago

2.0.0-beta.3

6 years ago

2.0.0-beta.2

6 years ago

2.0.0-beta.1

6 years ago

2.0.0-beta.0

6 years ago

2.0.0-alpha.2

6 years ago

1.0.16-9

6 years ago

1.0.16-8

6 years ago

1.0.16-7

6 years ago

1.0.16-6

6 years ago

1.0.16-5

6 years ago

1.0.16-2

6 years ago

1.0.16-1

6 years ago

1.0.16-0

6 years ago

1.0.13-2

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13-1

6 years ago

1.0.13

6 years ago

1.0.13-0

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-beta.6

7 years ago

1.0.0-beta.1

7 years ago

1.0.0-alpha.22

7 years ago

1.0.0-alpha17

7 years ago