Skip to content

Commit

Permalink
Merge branch 'release/2.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuananh committed Oct 12, 2017
2 parents d251715 + 859b3b6 commit 665f269
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser [pugixml](http://pugixml.org/), one of the fastest XML parser around.
[![npm](https://img.shields.io/npm/v/camaro.svg?style=flat-square)](https://npm.im/camaro)
[![Travis](https://img.shields.io/travis/tuananh/camaro.svg?label=Linux%20%26%20MacOS%20build&style=flat-square)](https://travis-ci.org/tuananh/camaro)
[![Travis](https://img.shields.io/travis/tuananh/camaro.svg?label=Linux%20%26%20macOS%20build&style=flat-square)](https://travis-ci.org/tuananh/camaro)
[![AppVeyor](https://img.shields.io/appveyor/ci/tuananh/camaro.svg?label=Windows%20build&style=flat-square)](https://ci.appveyor.com/project/tuananh/camaro)
[![David](https://img.shields.io/david/tuananh/camaro.svg?style=flat-square)](https://david-dm.org/tuananh/camaro)
[![npm](https://img.shields.io/npm/dt/camaro.svg?style=flat-square)](https://npm.im/camaro)
Expand Down Expand Up @@ -82,6 +82,12 @@ const template = {
const result = transform(xml, template)
```

### Namespaces

By default, a path `'//HotelSummary'` will transform all `HotelSummary` elements regardless of their namespaces. To only transform elements under a specific namespace, say `http://v3.hotel.wsapi.ean.com`, you can append the path with a filter:

'//HotelSummary[namespace-uri() = "http://v3.hotel.wsapi.ean.com"]'

## Licence

The MIT License
Expand Down
6 changes: 0 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ platform:
cache:
- '%APPDATA%\npm-cache'

# init:
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
install:
- ps: Install-Product node $env:nodejs_version $env:platform
- git submodule update --init --recursive
- npm config set spin false
- npm i -g npm node-pre-gyp --production
- npm install

build:
parallel: true
verbosity: minimal

test_script:
- npm test

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camaro",
"version": "2.0.4",
"version": "2.0.5",
"description": "Transforming XML to JSON using Node.js binding to native pugixml parser library",
"homepage": "https://github.com/tuananh/camaro",
"bugs": "https://github.com/tuananh/camaro/issues",
Expand Down
41 changes: 41 additions & 0 deletions test/array-in-array.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const t = require('tape')
const transform = require('../')

const xml = `
<element>
<item>outer0.arr0.0</item>
<item>outer0.arr0.1</item>
<item>outer0.arr0.2</item>
</element>
<element>
<item>outer0.arr1.0</item>
<item>outer0.arr1.1</item>
<item>outer0.arr1.2</item>
</element>
<element>
<item>outer1.arr0.0</item>
<item>outer1.arr0.1</item>
<item>outer1.arr0.2</item>
</element>
<element>
<item>outer1.arr1.0</item>
<item>outer1.arr1.1</item>
<item>outer1.arr1.2</item>
</element>
`

t.test('array-in-array test .// should only match nodes inside current node', (t) => {
const template = {
elements: ['//element', {
items: ['.//item', '.']
}]
}

const result = transform(xml, template)
t.equal(result.elements[0].items.length, 3, 'elements[0].items should have only 3 elements')
t.equal(result.elements[0].items[0], 'outer0.arr0.0', 'outer0.arr0.0')
t.equal(result.elements[0].items[1], 'outer0.arr0.1', 'outer0.arr0.1')
t.equal(result.elements[0].items[2], 'outer0.arr0.2', 'outer0.arr0.2')

t.end()
})

0 comments on commit 665f269

Please sign in to comment.