Skip to content

Commit e8ac4e4

Browse files
author
bgrana
committed
Update documentation
1 parent 80b4fcf commit e8ac4e4

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,29 @@ This parser takes an xml Wirecloud config file and returns a javascript object c
1616

1717
#### Initialization
1818

19-
Before trying to get any data, the library must be imported and the parser object created:
19+
Before trying to get any data, the library must be imported and the parser object created. There are two ways of creating a parser object. One is to pass a path as parameter to the constructor and the parser will read and parse the file indicated by the path:
2020

2121
```javascript
2222
var Parser = require('wirecloud-config-parser');
23-
var configParser = new Parser('parse/to/file');
23+
var configParser = new Parser('path/to/file');
24+
```
25+
26+
And the other is to give it an options object where you can specify either a path or directly the contents of a config file, as well as an option to validate the xml while building the object:
27+
28+
```javascript
29+
var Parser = require('wirecloud-config-parser');
30+
var content = fs.readFileSync('path/to/file').toString();
31+
var configParser = new Parser({content: content, validate: true});
32+
```
33+
>**NOTE:** If you give both the path and the content options in the object the parser will read from the file given in the path
34+
35+
#### Validate
36+
37+
Whether you have validated the XML content while building the object or not, you can use the validate function later to test if the XML complies with [Wirecloud's schema](https://raw.githubusercontent.com/Wirecloud/wirecloud/master/src/wirecloud/commons/utils/template/schemas/xml_schema.xsd):
38+
39+
```javascript
40+
configParser.validate();
41+
// it should return true or false
2442
```
2543

2644
#### Retrieve data

0 commit comments

Comments
 (0)