xml-twig 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,18 +37,6 @@ In my tests I parsed a 750 MB big XML file, the `node-expat` is around two times
|
|
|
37
37
|
|
|
38
38
|
## How to use it
|
|
39
39
|
|
|
40
|
-
#### Names and Definitions
|
|
41
|
-
|
|
42
|
-
In XML-Path, there are seven kinds of nodes: `element`, `attribute`, `text`, `namespace`, `processingInstruction`, `comment`, and `document`, see [Nodes at W3C](https://www.w3.org/TR/xpath-datamodel-31/#Node). XML documents are treated as trees of nodes.
|
|
43
|
-
|
|
44
|
-
The [Twig](./doc/twig.md#Twig) Class models a "some-kind" Element tree. I try to follow the [XML-Path](https://www.w3.org/TR/xpath/) conventions whenever possible to avoid confusion.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
#### XML-Namespaces
|
|
48
|
-
|
|
49
|
-
When the XML-Files uses [Namespaces](https://www.w3schools.com/xml/xml_namespaces.asp) then you can address the elements as they appear in the file, for example `cd:data`.
|
|
50
|
-
With option `{ namespaces : true }` you will get access to the `.namespace` property.
|
|
51
|
-
|
|
52
40
|
### Read XML Document
|
|
53
41
|
|
|
54
42
|
- **Read entire XML file at once**
|
|
@@ -90,7 +78,9 @@ With option `{ namespaces : true }` you will get access to the `.namespace` prop
|
|
|
90
78
|
|
|
91
79
|
- **Read XML Document in chucks**
|
|
92
80
|
|
|
93
|
-
The key feature of this module is to read and process XML files in chunks. You need to create handler functions for elements you like to process
|
|
81
|
+
The key feature of this module is to read and process XML files in chunks. You need to create handler functions for elements you like to process.<br>
|
|
82
|
+
The most notable difference to other parsers is the `purge()` and `purgeUpTo()` method. The parser reads the element and you decide how long you need to keep it in the memory.
|
|
83
|
+
In many cases you will purge it immediatly after you have used it but in some cases you may keep the element for later use. The parser knows the element position in the XML-Tree.
|
|
94
84
|
|
|
95
85
|
|
|
96
86
|
```
|
|
@@ -215,6 +205,18 @@ Be aware if you run methods like `elt.followingSibling()`, `elt.descendant()`, `
|
|
|
215
205
|
For details and other options, see [ParserOptions](./doc/twig.md#ParserOptions) and [TwigHandler](./doc/twig.md#TwigHandler)
|
|
216
206
|
|
|
217
207
|
|
|
208
|
+
#### Names and Definitions
|
|
209
|
+
|
|
210
|
+
In XML-Path, there are seven kinds of nodes: `element`, `attribute`, `text`, `namespace`, `processingInstruction`, `comment`, and `document`, see [Nodes at W3C](https://www.w3.org/TR/xpath-datamodel-31/#Node). XML documents are treated as trees of nodes.
|
|
211
|
+
|
|
212
|
+
The [Twig](./doc/twig.md#Twig) Class models a "some-kind" Element tree. I try to follow the [XML-Path](https://www.w3.org/TR/xpath/) conventions whenever possible to avoid confusion.
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
#### XML-Namespaces
|
|
216
|
+
|
|
217
|
+
When the XML-Files uses [Namespaces](https://www.w3schools.com/xml/xml_namespaces.asp) then you can address the elements as they appear in the file, for example `cd:data`.
|
|
218
|
+
With option `{ namespaces : true }` you will get access to the `.namespace` property.
|
|
219
|
+
|
|
218
220
|
### Access elements and attributes
|
|
219
221
|
|
|
220
222
|
#### Get XML Attributes
|
|
@@ -339,6 +341,8 @@ For methods which return a single **Twig** element (e.g. `elt.next("book")`) the
|
|
|
339
341
|
|
|
340
342
|
`.isLastChild` - **boolean**: `true` if the element is the last child in the parent
|
|
341
343
|
|
|
344
|
+
`.index` - **integer**: The postion (starting at 0) of the element within the parent. The root element returns always 0
|
|
345
|
+
|
|
342
346
|
`.name` - **string**: Name of the element/tag
|
|
343
347
|
|
|
344
348
|
`.tag` - **string**: Synonym for `name`
|