This repository was archived by the owner on Jan 7, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -22,21 +22,18 @@ $ npm install xml2json
2222``` javascript
2323var 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
10299Permission is hereby granted, free of charge, to any person obtaining a copy
103100of 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