Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit 712cc3c

Browse files
committed
Fixes code example
1 parent 68a1578 commit 712cc3c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

README.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,18 @@ $ npm install xml2json
2222
```javascript
2323
var parser = require('xml2json');
2424

25+
var xml = "<foo attr=\"value\">bar</foo>";
26+
console.log("input -> %s", xml)
27+
2528
// xml to json
26-
var xml = "<foo>bar</foo>";
27-
var json = parser.toJson(xml); //returns a string containing the JSON structure by default
28-
console.log(json);
29+
var json = parser.toJson(xml);
30+
console.log("to json -> %s", json);
2931

3032
// json to xml
31-
var json = {
32-
root: {
33-
name: {'$t': 'John', id:'idx'} // $t for text, and all others will be attributes
34-
}
35-
};
36-
var xml = parser.toXml(json); //returns xml <root><name for="idx">John</name></root>
37-
console.log(xml)
38-
33+
var xml = parser.toXml(json);
34+
console.log("back to xml -> %s", xml)
3935
```
36+
4037
## API
4138

4239
```javascript
@@ -97,7 +94,7 @@ var options = {
9794
## License
9895
(The MIT License)
9996

100-
Copyright 2015 BugLabs. All rights reserved.
97+
Copyright (c) 2016 xml2json AUTHORS
10198

10299
Permission is hereby granted, free of charge, to any person obtaining a copy
103100
of this software and associated documentation files (the "Software"), to

example.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var parser = require('./index');
2+
3+
// xml to json
4+
var xml = "<foo attr=\"value\">bar</foo>";
5+
console.log("input -> %s", xml)
6+
var json = parser.toJson(xml);
7+
console.log("to json -> %s", json);
8+
9+
var xml = parser.toXml(json);
10+
console.log("back to xml -> %s", xml)

0 commit comments

Comments
 (0)