You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,29 @@ This parser takes an xml Wirecloud config file and returns a javascript object c
16
16
17
17
#### Initialization
18
18
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:
20
20
21
21
```javascript
22
22
var Parser =require('wirecloud-config-parser');
23
-
var configParser =newParser('parse/to/file');
23
+
var configParser =newParser('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 =newParser({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):
0 commit comments