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

Restore xml children order #442

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,59 @@ value})``. Possible options are:
}
```
Added in 0.4.6
* `sourcemap` (default: `false`): Allows exporting node positions in the XML
source document. By default it adds to all nodes a non-enumerable property
called `$source` (doesn't show up during enumeration of the properties on the objects).
The name of the property and whether or not you want it enumerable can be
configured with the options below.
* `sourcemapkey` (default: `$source`): Change the key to use when exporting sourcemaps.
* `sourcemapEnumerable` (default: `false`): Make the sourcemap enumerable (visible).
Note that converting back the JSON to XML will include `$source` attributes
if you make them enumerable. Here's a small example:
```javascript
xml = "<a>\n <b>hello</b>\n</a>";
xml2js.parseString(xml, {sourcemap: true, sourcemapEnumerable: true}, (err, parsed) => {
console.log(JSON.stringify(parsed));
});
```
This will output:
```json
{
"a": {
"$source": {
"start": {
"line": 0,
"column": 3,
"position": 3
},
"end": {
"line": 2,
"column": 4,
"position": 23
}
},
"b": [
{
"_": "hello",
"$source": {
"start": {
"line": 1,
"column": 5,
"position": 9
},
"end": {
"line": 1,
"column": 14,
"position": 18
}
}
}
]
}
}
```
If `sourcemapEnumerable` was not set, `$source` wouldn't appear in the generated
JSON but would be accessible the same way.

Options for the `Builder` class
-------------------------------
Expand Down
118 changes: 83 additions & 35 deletions lib/builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/defaults.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"David Wood <[email protected]> (http://codesleuth.co.uk/)",
"Nicolas Maquet (https://github.com/nmaquet)",
"Lovell Fuller (http://lovell.info/)",
"Jean-Christophe Hoelt (http://github.com/j3k0)",
"d3adc0d3 (https://github.com/d3adc0d3)"
],
"main": "./lib/xml2js",
Expand Down
Loading