From 687c01a30342cb39462f01151be1c29501abb339 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Wed, 4 Oct 2017 10:34:56 +0700 Subject: [PATCH 1/6] ci: remove appveyor build --- appveyor.yml | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index da1bd66..3a896ce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,9 +34,9 @@ install: - npm i -g npm node-pre-gyp --production - npm install -build: - parallel: true - verbosity: minimal +# 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", From 0370e322451b69a97db0c6e894ee67ef8fdd2f44 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Wed, 4 Oct 2017 10:40:04 +0700 Subject: [PATCH 2/6] ci: remove appveyor build comment, update docs typo --- README.md | 2 +- appveyor.yml | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 1b841d2..7c6ff9a 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) diff --git a/appveyor.yml b/appveyor.yml index 3a896ce..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 From 41f7c71cfa680bdaf6abf9e564f87f072ce42877 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Thu, 5 Oct 2017 15:17:57 +0700 Subject: [PATCH 3/6] test: add failed tests --- package.json | 2 +- test/array-in-array.test.js | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/array-in-array.test.js diff --git a/package.json b/package.json index d0e6367..2c62d25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "camaro", - "version": "2.0.5", + "version": "3.0.0", "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..0357ad4 --- /dev/null +++ b/test/array-in-array.test.js @@ -0,0 +1,50 @@ +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', (t) => { + const template = { + arrayOuter: ['//arrayOuter', { + arrayInner: ['//arrayInner', { + item: 'item' + }] + }] + } + + const result = transform(xml, template) + // console.log(JSON.stringify(result, null, 4)) + t.equal(result.arrayOuter[0].arrayInner.length, 2, 'inner should have only 2 elements') + t.equal(result.arrayOuter[0].arrayInner[0].item, 'outer0.arr0.0', 'outer0.arr0.0') + t.equal(result.arrayOuter[0].arrayInner[1].item, 'outer0.arr0.1', 'outer0.arr0.1') + + t.end() +}) \ No newline at end of file From a2b9b5e4f01f109c9ac73d2e6b6fd76f87e84018 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Fri, 6 Oct 2017 08:29:04 +0700 Subject: [PATCH 4/6] test: update test --- test/array-in-array.test.js | 65 ++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/test/array-in-array.test.js b/test/array-in-array.test.js index 0357ad4..f3eccb1 100644 --- a/test/array-in-array.test.js +++ b/test/array-in-array.test.js @@ -1,50 +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 - - - +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', (t) => { +t.test('array-in-array test .// should only match nodes inside current node', (t) => { const template = { - arrayOuter: ['//arrayOuter', { - arrayInner: ['//arrayInner', { - item: 'item' - }] + elements: ['//element', { + items: ['.//item', '.'] }] } const result = transform(xml, template) - // console.log(JSON.stringify(result, null, 4)) - t.equal(result.arrayOuter[0].arrayInner.length, 2, 'inner should have only 2 elements') - t.equal(result.arrayOuter[0].arrayInner[0].item, 'outer0.arr0.0', 'outer0.arr0.0') - t.equal(result.arrayOuter[0].arrayInner[1].item, 'outer0.arr0.1', 'outer0.arr0.1') + 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 From 9d378cbf399f0221cb6520bc80171ed5656fe3b6 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Fri, 6 Oct 2017 08:29:50 +0700 Subject: [PATCH 5/6] fix: wrong version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c62d25..d0e6367 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "camaro", - "version": "3.0.0", + "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", From 7533ec3290707f2ba19d23f87e26322c131dc02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Akseli=20Pal=C3=A9n?= Date: Thu, 12 Oct 2017 20:16:19 +0300 Subject: [PATCH 6/6] Document how namespaces are handled --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7c6ff9a..a96d0db 100644 --- a/README.md +++ b/README.md @@ -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