Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby-transformer-xml): Update README #13921

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 130 additions & 15 deletions packages/gatsby-transformer-xml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ So if your project has a `books.xml` with
</catalog>
```

Then the following 2 nodes will be created
The plugin 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": {},
Expand All @@ -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": ""
Expand All @@ -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": ""
Expand All @@ -100,16 +153,22 @@ 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
}
}
}
}
Expand All @@ -120,19 +179,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.