From f5eaacc6de0b4eed52aa761e58f3a9e5bffac3c0 Mon Sep 17 00:00:00 2001 From: Violeta Menendez Gonzalez Date: Tue, 7 May 2019 16:55:05 +0100 Subject: [PATCH 1/3] Update gatsby-transformer-xml README.md --- packages/gatsby-transformer-xml/README.md | 146 +++++++++++++++++++--- 1 file changed, 130 insertions(+), 16 deletions(-) diff --git a/packages/gatsby-transformer-xml/README.md b/packages/gatsby-transformer-xml/README.md index 46955e6695611..8977ffbf9e4f1 100644 --- a/packages/gatsby-transformer-xml/README.md +++ b/packages/gatsby-transformer-xml/README.md @@ -44,10 +44,15 @@ So if your project has a `books.xml` with ``` -Then the following 2 nodes will be created +The pluging uses [xml-parser](https://www.npmjs.com/package/xml-parser) to convert it to json ```json { + "declaration": { + "attributes": { + "version": "1.0" + } + }, "root": { "name": "catalog", "attributes": {}, @@ -69,6 +74,30 @@ Then the following 2 nodes will be created "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": "" @@ -90,6 +119,30 @@ Then the following 2 nodes will be created "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": "" @@ -100,16 +153,21 @@ Then the following 2 nodes will be created } ``` +which then is used to create the nodes. + ## How to query You'd be able to query your books like: ```graphql -{ - allBooks { + allBooksXml { edges { node { - content + name + xmlChildren { + name + content + } } } } @@ -120,19 +178,75 @@ Which would return: ```javascript { - allBooks: { - edges: [ - { - node: { - content: "Gambardella, Matthew", - }, - }, - { - node: { - content: "XML Developer's Guide", + "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. From bcd1c5713efff9674da6cf1d7a1b9a57bab061d9 Mon Sep 17 00:00:00 2001 From: Lennart Date: Wed, 8 May 2019 09:55:58 +0200 Subject: [PATCH 2/3] fix typos --- packages/gatsby-transformer-xml/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-transformer-xml/README.md b/packages/gatsby-transformer-xml/README.md index 8977ffbf9e4f1..3c429d3338cd6 100644 --- a/packages/gatsby-transformer-xml/README.md +++ b/packages/gatsby-transformer-xml/README.md @@ -44,7 +44,7 @@ So if your project has a `books.xml` with ``` -The pluging uses [xml-parser](https://www.npmjs.com/package/xml-parser) to convert it to json +The plugin uses [xml-parser](https://www.npmjs.com/package/xml-parser) to convert it to json ```json { @@ -153,7 +153,7 @@ The pluging uses [xml-parser](https://www.npmjs.com/package/xml-parser) to conve } ``` -which then is used to create the nodes. +Which then is used to create the nodes. ## How to query From df925db398205997e33834f41f85da08b624b07a Mon Sep 17 00:00:00 2001 From: Lennart Date: Wed, 8 May 2019 09:57:56 +0200 Subject: [PATCH 3/3] add missing curly bracket --- packages/gatsby-transformer-xml/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gatsby-transformer-xml/README.md b/packages/gatsby-transformer-xml/README.md index 3c429d3338cd6..c175bbeac92c8 100644 --- a/packages/gatsby-transformer-xml/README.md +++ b/packages/gatsby-transformer-xml/README.md @@ -160,6 +160,7 @@ Which then is used to create the nodes. You'd be able to query your books like: ```graphql +{ allBooksXml { edges { node {