diff --git a/README.md b/README.md index 1b841d2..a96d0db 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/appveyor.yml b/appveyor.yml index da1bd66..87c321f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,8 +25,6 @@ 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 @@ -34,10 +32,6 @@ install: - npm i -g npm node-pre-gyp --production - npm install -build: - parallel: true - verbosity: minimal - test_script: - npm test diff --git a/package.json b/package.json index 87376af..d0e6367 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/array-in-array.test.js b/test/array-in-array.test.js new file mode 100644 index 0000000..f3eccb1 --- /dev/null +++ b/test/array-in-array.test.js @@ -0,0 +1,41 @@ +const t = require('tape') +const transform = require('../') + +const xml = ` + + outer0.arr0.0 + outer0.arr0.1 + outer0.arr0.2 + + + outer0.arr1.0 + outer0.arr1.1 + outer0.arr1.2 + + + outer1.arr0.0 + outer1.arr0.1 + outer1.arr0.2 + + + outer1.arr1.0 + outer1.arr1.1 + outer1.arr1.2 + +` + +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() +}) \ No newline at end of file