Last active
January 1, 2016 04:28
-
-
Save hbi99/8091760 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = '<data><user id="1" name="Hakan Bilgin">'+ | |
'<mail>hbi@bredband.net</mail></user></data>', | |
doc = Defiant.xmlFromString(str), | |
obj = Defiant.node.toJSON(doc.documentElement); | |
console.log( JSON.stringify(obj, null, '\t') ); | |
/* | |
{ | |
"user": { | |
"@id": 1, | |
"@name": "Hakan Bilgin", | |
"mail": "hbi@bredband.net" | |
} | |
} | |
*/ | |
// Changing it back to XML | |
var doc2 = JSON.toXML( obj ); | |
console.log( Defiant.node.prettyPrint( doc2 ) ); | |
/* | |
<?xml version="1.0" encoding="UTF-8"?> | |
<d:data xmlns:d="defiant-namespace> | |
<user id="1" name="Hakan Bilgin"> | |
<mail>hbi@bredband.net</mail> | |
</user> | |
</d:data> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment