This repository was archived by the owner on Jan 7, 2021. It is now read-only.
File tree 2 files changed +19
-12
lines changed
2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -22,21 +22,18 @@ $ npm install xml2json
22
22
``` javascript
23
23
var parser = require (' xml2json' );
24
24
25
+ var xml = " <foo attr=\" value\" >bar</foo>" ;
26
+ console .log (" input -> %s" , xml)
27
+
25
28
// 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);
29
31
30
32
// 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)
39
35
```
36
+
40
37
## API
41
38
42
39
``` javascript
@@ -97,7 +94,7 @@ var options = {
97
94
## License
98
95
(The MIT License)
99
96
100
- Copyright 2015 BugLabs. All rights reserved.
97
+ Copyright (c) 2016 xml2json AUTHORS
101
98
102
99
Permission is hereby granted, free of charge, to any person obtaining a copy
103
100
of this software and associated documentation files (the "Software"), to
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments