From 115e66f6a7bdc11ceee87890faae160d67accf44 Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Sat, 8 Sep 2012 08:16:34 -0400 Subject: [PATCH 1/4] wip readme --- README.md | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d7c6b1c..4ccb482 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,44 @@ It does not parse the following elements: * Entity declarations * Comments -## Installation -`npm install xml2json` +## Installation +``` +$ npm install xml2json +``` ## Usage -```javascript +``` var parser = require('xml2json'); var xml = "bar"; -var json = parser.toJson(xml); //returns an string containing the json structure by default +var json = parser.toJson(xml); //returns a string containing the JSON structure by default console.log(json); ``` +### Options + +* **object:** Returns a Javascript object instead of a JSON string +* **reversible:** Makes the JSON reversible to XML (*) +* **coerce:** Makes type coercion +* **sanitize:** Sanitizes the following characters: + +| Character | Escaped | +| --------- | ------- | +| `<` | `<` | +| `>` | `>` | +| `(` | `(`| +| | | +| | | + +* **trim:** + +``` +options = { + object: false, + reversible: false, + coerce: true, + sanitize: true, + trim: true }; +``` * if you want to get the Javascript object then you might want to invoke parser.toJson(xml, {object: true}); * if you want a reversible json to xml then you should use parser.toJson(xml, {reversible: true}); * if you want to keep xml space text then you should use `options.space`, `parser.toJson(xml, {space: true})`; @@ -26,7 +53,7 @@ console.log(json); ## License (The MIT License) -Copyright 2011 BugLabs. All rights reserved. +Copyright 2012 BugLabs. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to From 5250374cfbbfe50ae38eeada150ed2b3bb6c8a09 Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Sat, 8 Sep 2012 08:39:53 -0400 Subject: [PATCH 2/4] Moar readme --- README.md | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4ccb482..f32c062 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ It does not parse the following elements: -* CDATA sections +* CDATA sections (*) * Processing instructions * XML declarations * Entity declarations @@ -21,34 +21,47 @@ var xml = "bar"; var json = parser.toJson(xml); //returns a string containing the JSON structure by default console.log(json); ``` -### Options +## API -* **object:** Returns a Javascript object instead of a JSON string -* **reversible:** Makes the JSON reversible to XML (*) -* **coerce:** Makes type coercion -* **sanitize:** Sanitizes the following characters: - -| Character | Escaped | -| --------- | ------- | -| `<` | `<` | -| `>` | `>` | -| `(` | `(`| -| | | -| | | +``` +parser.toJson(xml, options); +``` +``` +parser.toXml(json, options); +``` -* **trim:** +### Options object ``` -options = { +var options = { object: false, reversible: false, coerce: true, sanitize: true, trim: true }; ``` -* if you want to get the Javascript object then you might want to invoke parser.toJson(xml, {object: true}); -* if you want a reversible json to xml then you should use parser.toJson(xml, {reversible: true}); -* if you want to keep xml space text then you should use `options.space`, `parser.toJson(xml, {space: true})`; + +* **object:** Returns a Javascript object instead of a JSON string +* **reversible:** Makes the JSON reversible to XML (*) +* **coerce:** Makes type coercion. i.e.: numbers and booleans present in attributes and element values are converted from string to its correspondent data types. +* **trim:** Removes leading and trailing whitespaces as well as line terminators in element values. +* **sanitize:** Sanitizes the following characters: + +``` +var chars = { '<': '<', + '>': '>', + '(': '(', + ')': ')', + '#': '#', + '&': '&', + '"': '"', + "'": ''' }; +``` + + + + +(*) xml2json tranforms CDATA content to JSON, but it doesn't generate a reversible structure. ## License (The MIT License) From 941f325b7038963eb0feb02927be4c8f54dbb608 Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Sat, 8 Sep 2012 08:40:49 -0400 Subject: [PATCH 3/4] gitignores .DS_Store --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1bd7226..24211de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules *.swp +*.DS_Store From ef331c47ffc88ee950b619d11a1e131e5af1966e Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Sat, 8 Sep 2012 09:43:46 -0300 Subject: [PATCH 4/4] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f32c062..1ec3f09 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ $ npm install xml2json ``` ## Usage -``` +```javascript var parser = require('xml2json'); var xml = "bar"; @@ -23,16 +23,16 @@ console.log(json); ``` ## API -``` +```javascript parser.toJson(xml, options); ``` -``` +```javascript parser.toXml(json, options); ``` ### Options object -``` +```javascript var options = { object: false, reversible: false, @@ -47,7 +47,7 @@ var options = { * **trim:** Removes leading and trailing whitespaces as well as line terminators in element values. * **sanitize:** Sanitizes the following characters: -``` +```javascript var chars = { '<': '<', '>': '>', '(': '(',