Skip to content

Commit

Permalink
Better README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
chilts committed Oct 14, 2014
1 parent 2a8c25d commit 020433b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var convert = require('data2xml')();
Note: in each example, I am leaving out the XML declaration (controlled by the `xmlDecl` option). I
am also pretty printing the output - the package doesn't do this for you!

```
```js
var convert = require('data2xml')();

convert(
Expand All @@ -61,9 +61,11 @@ convert(
},
}
);
```

=>
Will produce:

```xml
<TopLevelLement xmlns="http://chilts.org/xml/namespace">
<SimpleElement>A simple element</SimpleElement>
<ComplexElement>
Expand All @@ -76,7 +78,7 @@ convert(
If you want an element containing data you can do it one of two ways. A simple piece of data will work, but if you want
attributes you need to specify the value in the element object. You can also specify a CDATA element too.

```
```js
convert(
'TopLevelElement',
{
Expand All @@ -91,9 +93,11 @@ convert(
},
}
);
```

=>
Will produce:

```xml
<TopLevelLement xmlns="http://chilts.org/xml/namespace">
<SimpleData>Simple Value</SimpleData>
<ComplexData type="color">White</ComplexData>
Expand All @@ -103,7 +107,7 @@ convert(

You can also specify which properties your attributes and values are in (using the same example as above):

```
```js
var convert = require('data2xml')({ attrProp : '@', valProp : '#', cdataProp : '%' });
convert(
'TopLevelElement',
Expand All @@ -118,9 +122,11 @@ convert(
'%' : 'This is <bold>bold</bold>.',
},
});
```

=>
Will produce:

```xml
<TopLevelLement xmlns="http://chilts.org/xml/namespace">
<SimpleData>Simple Value</SimpleData>
<ComplexData type="color">White</ComplexData>
Expand All @@ -131,7 +137,7 @@ convert(
You can also specify what you want to do with undefined or null values. Choose between 'omit' (the default), 'empty' or
'closed'.

```
```js
var convert = require('data2xml')({ 'undefined' : 'empty', 'null' : 'closed', });
convert(
'TopLevelElement',
Expand All @@ -144,9 +150,11 @@ convert(
Undefined : undefined,
Null : null,
});
```

=>
Will produce:

```xml
<TopLevelLement xmlns="http://chilts.org/xml/namespace">
<SimpleData>Simple Value</SimpleData>
<ComplexData type="color">White</ComplexData>
Expand All @@ -157,7 +165,7 @@ convert(

If you want an array, just put one in there:

```
```js
convert('TopLevelElement', {
MyArray : [
'Simple Value',
Expand All @@ -167,9 +175,11 @@ convert('TopLevelElement', {
}
],
});
```

=>
Will produce:

```xml
<TopLevelLement xmlns="http://chilts.org/xml/namespace">
<MyArray>Simple Value</MyArray>
<MyArray type="color">White</MyArray>
Expand All @@ -178,7 +188,7 @@ convert('TopLevelElement', {

You can also enclose values in CDATA, by using `_cdata` in place of `_value`:

```
```js
convert(
'TopLevelElement',
{
Expand All @@ -189,9 +199,11 @@ convert(
}
}
);
```

=>
Will produce:

```xml
<TopLevelLement xmlns="http://chilts.org/xml/namespace">
<SimpleData>Simple Value</SimpleData>
<ComplexData type="color"><![CDATA[<em>White</em>]]></ComplexData>
Expand Down

0 comments on commit 020433b

Please sign in to comment.