xml-twig 1.2.81 → 1.2.82
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/doc/twig.md +93 -100
- package/package.json +1 -1
package/doc/twig.md
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
## Functions
|
|
33
33
|
|
|
34
34
|
<dl>
|
|
35
|
-
<dt><a href="#createParser">createParser(handler, options)</a></dt>
|
|
35
|
+
<dt><a href="#createParser">createParser(handler, [options])</a></dt>
|
|
36
36
|
<dd><p>Create a new Twig parser</p>
|
|
37
37
|
</dd>
|
|
38
38
|
</dl>
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
Element can be specified as string, Regular Expression, custom function, <code>Twig.Root</code> or <code>Twig.Any</code><br>
|
|
49
49
|
You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
50
50
|
</dd>
|
|
51
|
-
<dt><a href="#HandlerCondition">HandlerCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#HandlerConditionFilter">HandlerConditionFilter</a></code> | <code>RootHandler</code> | <code>AnyHandler</code></dt>
|
|
51
|
+
<dt><a href="#HandlerCondition">HandlerCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#HandlerConditionFilter">HandlerConditionFilter</a></code> | <code>RootHandler</code> | <code>AnyHandler</code> | <code>undefined</code></dt>
|
|
52
52
|
<dd><p>Condition to specify when handler shall be called<br> </p>
|
|
53
53
|
<ul>
|
|
54
54
|
<li>If <code>undefined</code>, then all elements are returned.<br> </li>
|
|
@@ -62,10 +62,10 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
|
62
62
|
<dt><a href="#HandlerFunction">HandlerFunction</a></dt>
|
|
63
63
|
<dd><p>Handler function for Twig objects, i.e. the way you like to use the XML element.</p>
|
|
64
64
|
</dd>
|
|
65
|
-
<dt><a href="#HandlerConditionFilter">HandlerConditionFilter</a>
|
|
65
|
+
<dt><a href="#HandlerConditionFilter">HandlerConditionFilter</a> ⇒ <code>boolean</code></dt>
|
|
66
66
|
<dd><p>Custom filter function to specify when handler shall be called</p>
|
|
67
67
|
</dd>
|
|
68
|
-
<dt><a href="#ElementCondition">ElementCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#ElementConditionFilter">ElementConditionFilter</a></code> | <code><a href="#Twig">Twig</a></code></dt>
|
|
68
|
+
<dt><a href="#ElementCondition">ElementCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#ElementConditionFilter">ElementConditionFilter</a></code> | <code><a href="#Twig">Twig</a></code> | <code>undefined</code></dt>
|
|
69
69
|
<dd><p>Optional condition to get elements<br> </p>
|
|
70
70
|
<ul>
|
|
71
71
|
<li>If <code>undefined</code>, then all elements are returned.<br> </li>
|
|
@@ -75,7 +75,7 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
|
75
75
|
<li>Use <a href="#Twig">Twig</a> object to find a specific element</li>
|
|
76
76
|
</ul>
|
|
77
77
|
</dd>
|
|
78
|
-
<dt><a href="#ElementConditionFilter">ElementConditionFilter</a>
|
|
78
|
+
<dt><a href="#ElementConditionFilter">ElementConditionFilter</a> ⇒ <code>boolean</code></dt>
|
|
79
79
|
<dd><p>Custom filter function to select desired elements</p>
|
|
80
80
|
</dd>
|
|
81
81
|
<dt><a href="#AttributeCondition">AttributeCondition</a> : <code>string</code> | <code>RegExp</code> | <code><a href="#AttributeConditionFilter">AttributeConditionFilter</a></code></dt>
|
|
@@ -111,7 +111,7 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
|
111
111
|
|
|
112
112
|
* [Twig](#Twig)
|
|
113
113
|
* [new Twig()](#new_Twig_new)
|
|
114
|
-
* [new Twig(name, parent, attributes, index)](#new_Twig_new)
|
|
114
|
+
* [new Twig(name, [parent], [attributes], [index])](#new_Twig_new)
|
|
115
115
|
* [.attributes](#Twig+attributes) ℗
|
|
116
116
|
* [.text](#Twig+text) ℗
|
|
117
117
|
* [.name](#Twig+name) ℗
|
|
@@ -164,8 +164,8 @@ You can specify a <code>function</code> or a <code>event</code> name</p>
|
|
|
164
164
|
* [.addElement](#Twig+addElement) ⇒ [<code>Twig</code>](#Twig)
|
|
165
165
|
* [.delete](#Twig+delete)
|
|
166
166
|
* [.setRoot(name)](#Twig+setRoot) ℗
|
|
167
|
-
* [.filterElements(elements, condition)](#Twig+filterElements) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
168
|
-
* [.testElement(element, condition)](#Twig+testElement) ⇒ <code>boolean</code>
|
|
167
|
+
* [.filterElements(elements, [condition])](#Twig+filterElements) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
168
|
+
* [.testElement(element, [condition])](#Twig+testElement) ⇒ <code>boolean</code>
|
|
169
169
|
|
|
170
170
|
<a name="new_Twig_new"></a>
|
|
171
171
|
|
|
@@ -174,16 +174,16 @@ Generic class modeling a XML Node
|
|
|
174
174
|
|
|
175
175
|
<a name="new_Twig_new"></a>
|
|
176
176
|
|
|
177
|
-
### new Twig(name, parent, attributes, index)
|
|
177
|
+
### new Twig(name, [parent], [attributes], [index])
|
|
178
178
|
Create a new Twig object
|
|
179
179
|
|
|
180
180
|
|
|
181
181
|
| Param | Type | Description |
|
|
182
182
|
| --- | --- | --- |
|
|
183
183
|
| name | <code>string</code> | The name of the XML element |
|
|
184
|
-
| parent | [<code>Twig</code>](#Twig) | The parent object |
|
|
185
|
-
| attributes | <code>object</code> | Attribute object |
|
|
186
|
-
| index | <code>string</code> \| <code>number</code> | Position name 'first', 'last' or the position in the current `children` array.<br>Defaults to 'last' |
|
|
184
|
+
| [parent] | [<code>Twig</code>](#Twig) | The parent object |
|
|
185
|
+
| [attributes] | <code>object</code> | Attribute object |
|
|
186
|
+
| [index] | <code>string</code> \| <code>number</code> | Position name 'first', 'last' or the position in the current `children` array.<br>Defaults to 'last' |
|
|
187
187
|
|
|
188
188
|
<a name="Twig+attributes"></a>
|
|
189
189
|
|
|
@@ -266,7 +266,7 @@ Purges up to the elt element. This allows you to keep part of the tree in memory
|
|
|
266
266
|
|
|
267
267
|
| Param | Type | Description |
|
|
268
268
|
| --- | --- | --- |
|
|
269
|
-
| elt | [<code>Twig</code>](#Twig) | Up to this element the tree will be purged. The `elt` object itself is not purged.<br> If `undefined` then the current element is purged (i.e. `purge()`) |
|
|
269
|
+
| [elt] | [<code>Twig</code>](#Twig) | Up to this element the tree will be purged. The `elt` object itself is not purged.<br> If `undefined` then the current element is purged (i.e. `purge()`) |
|
|
270
270
|
|
|
271
271
|
<a name="Twig+escapeEntity"></a>
|
|
272
272
|
|
|
@@ -380,7 +380,7 @@ Internal recursive function used by `writer()`
|
|
|
380
380
|
| Param | Type | Description |
|
|
381
381
|
| --- | --- | --- |
|
|
382
382
|
| xw | <code>XMLWriter</code> | The writer object |
|
|
383
|
-
|
|
|
383
|
+
| childArray | [<code>Array.<Twig></code>](#Twig) | Array of child elements |
|
|
384
384
|
|
|
385
385
|
<a name="Twig+writer"></a>
|
|
386
386
|
|
|
@@ -403,7 +403,7 @@ Returns attribute value or `null` if not found.<br>
|
|
|
403
403
|
|
|
404
404
|
| Param | Type | Description |
|
|
405
405
|
| --- | --- | --- |
|
|
406
|
-
| condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attribute |
|
|
406
|
+
| [condition] | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attribute |
|
|
407
407
|
|
|
408
408
|
<a name="Twig+attributes"></a>
|
|
409
409
|
|
|
@@ -434,8 +434,8 @@ Retrieve or update XML attribute. For update, the condition must be a string, i.
|
|
|
434
434
|
|
|
435
435
|
| Param | Type | Description |
|
|
436
436
|
| --- | --- | --- |
|
|
437
|
-
| condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attributes |
|
|
438
|
-
| value | <code>string</code> \| <code>number</code> \| <code>bigint</code> \| <code>boolean</code> | New value of the attribute.<br>If `undefined` then existing attributes is returned. |
|
|
437
|
+
| [condition] | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attributes |
|
|
438
|
+
| [value] | <code>string</code> \| <code>number</code> \| <code>bigint</code> \| <code>boolean</code> | New value of the attribute.<br>If `undefined` then existing attributes is returned. |
|
|
439
439
|
|
|
440
440
|
**Example**
|
|
441
441
|
```js
|
|
@@ -480,7 +480,7 @@ All children, optionally matching `condition` of the current element or empty ar
|
|
|
480
480
|
|
|
481
481
|
| Param | Type | Description |
|
|
482
482
|
| --- | --- | --- |
|
|
483
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
483
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
484
484
|
|
|
485
485
|
<a name="Twig+next"></a>
|
|
486
486
|
|
|
@@ -493,7 +493,7 @@ Returns the next matching element.
|
|
|
493
493
|
|
|
494
494
|
| Param | Type | Description |
|
|
495
495
|
| --- | --- | --- |
|
|
496
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
496
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
497
497
|
|
|
498
498
|
<a name="Twig+previous"></a>
|
|
499
499
|
|
|
@@ -506,7 +506,7 @@ Returns the previous matching element.
|
|
|
506
506
|
|
|
507
507
|
| Param | Type | Description |
|
|
508
508
|
| --- | --- | --- |
|
|
509
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
509
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
510
510
|
|
|
511
511
|
<a name="Twig+first"></a>
|
|
512
512
|
|
|
@@ -518,7 +518,7 @@ Returns the first matching element. This is usually the root element
|
|
|
518
518
|
|
|
519
519
|
| Param | Type | Description |
|
|
520
520
|
| --- | --- | --- |
|
|
521
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
521
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
522
522
|
|
|
523
523
|
<a name="Twig+last"></a>
|
|
524
524
|
|
|
@@ -530,7 +530,7 @@ Returns the last matching element.
|
|
|
530
530
|
|
|
531
531
|
| Param | Type | Description |
|
|
532
532
|
| --- | --- | --- |
|
|
533
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
533
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
534
534
|
|
|
535
535
|
<a name="Twig+isFirstChild"></a>
|
|
536
536
|
|
|
@@ -556,7 +556,7 @@ Returns descendants (children, grandchildren, etc.) of the current element
|
|
|
556
556
|
|
|
557
557
|
| Param | Type | Description |
|
|
558
558
|
| --- | --- | --- |
|
|
559
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
559
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
560
560
|
|
|
561
561
|
<a name="Twig+descendantOrSelf"></a>
|
|
562
562
|
|
|
@@ -568,7 +568,7 @@ Returns descendants (children, grandchildren, etc.) of the current element and t
|
|
|
568
568
|
|
|
569
569
|
| Param | Type | Description |
|
|
570
570
|
| --- | --- | --- |
|
|
571
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
571
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
572
572
|
|
|
573
573
|
<a name="Twig+ancestor"></a>
|
|
574
574
|
|
|
@@ -580,7 +580,7 @@ Returns ancestors (parent, grandparent, etc.) of the current element
|
|
|
580
580
|
|
|
581
581
|
| Param | Type | Description |
|
|
582
582
|
| --- | --- | --- |
|
|
583
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
583
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
584
584
|
|
|
585
585
|
<a name="Twig+ancestorOrSelf"></a>
|
|
586
586
|
|
|
@@ -592,7 +592,7 @@ Returns ancestors (parent, grandparent, etc.) of the current element and the cu
|
|
|
592
592
|
|
|
593
593
|
| Param | Type | Description |
|
|
594
594
|
| --- | --- | --- |
|
|
595
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
595
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
596
596
|
|
|
597
597
|
<a name="Twig+sibling"></a>
|
|
598
598
|
|
|
@@ -604,7 +604,7 @@ Returns all sibling element of the current element
|
|
|
604
604
|
|
|
605
605
|
| Param | Type | Description |
|
|
606
606
|
| --- | --- | --- |
|
|
607
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
607
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
608
608
|
|
|
609
609
|
<a name="Twig+siblingOrSelf"></a>
|
|
610
610
|
|
|
@@ -616,7 +616,7 @@ Returns all sibling element of the current element and the current element itsel
|
|
|
616
616
|
|
|
617
617
|
| Param | Type | Description |
|
|
618
618
|
| --- | --- | --- |
|
|
619
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
619
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
620
620
|
|
|
621
621
|
<a name="Twig+followingSibling"></a>
|
|
622
622
|
|
|
@@ -628,7 +628,7 @@ Returns all following sibling element of the current element
|
|
|
628
628
|
|
|
629
629
|
| Param | Type | Description |
|
|
630
630
|
| --- | --- | --- |
|
|
631
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
631
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
632
632
|
|
|
633
633
|
<a name="Twig+precedingSibling"></a>
|
|
634
634
|
|
|
@@ -640,7 +640,7 @@ Returns all preceding sibling element of the current element
|
|
|
640
640
|
|
|
641
641
|
| Param | Type | Description |
|
|
642
642
|
| --- | --- | --- |
|
|
643
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
643
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
644
644
|
|
|
645
645
|
<a name="Twig+nextSibling"></a>
|
|
646
646
|
|
|
@@ -652,7 +652,7 @@ Returns next sibling element of the current element
|
|
|
652
652
|
|
|
653
653
|
| Param | Type | Description |
|
|
654
654
|
| --- | --- | --- |
|
|
655
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
655
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
656
656
|
|
|
657
657
|
<a name="Twig+prevSibling"></a>
|
|
658
658
|
|
|
@@ -664,7 +664,7 @@ Returns previous sibling element of the current element
|
|
|
664
664
|
|
|
665
665
|
| Param | Type | Description |
|
|
666
666
|
| --- | --- | --- |
|
|
667
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
667
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
668
668
|
|
|
669
669
|
<a name="Twig+find"></a>
|
|
670
670
|
|
|
@@ -689,9 +689,9 @@ Add a new element in the current element
|
|
|
689
689
|
| Param | Type | Description |
|
|
690
690
|
| --- | --- | --- |
|
|
691
691
|
| name | <code>string</code> | The tag name |
|
|
692
|
-
| text | <code>string</code> | Text of the element |
|
|
693
|
-
| attributes | <code>object</code> | Element attributes |
|
|
694
|
-
| position | <code>name</code> \| <code>number</code> | Position name 'first', 'last' or the position in the `children` |
|
|
692
|
+
| [text] | <code>string</code> | Text of the element |
|
|
693
|
+
| [attributes] | <code>object</code> | Element attributes |
|
|
694
|
+
| [position] | <code>name</code> \| <code>number</code> | Position name 'first', 'last' or the position in the `children` |
|
|
695
695
|
|
|
696
696
|
<a name="Twig+delete"></a>
|
|
697
697
|
|
|
@@ -713,7 +713,7 @@ Sets the name of root element. In some cases the root is created before the XML-
|
|
|
713
713
|
|
|
714
714
|
<a name="Twig+filterElements"></a>
|
|
715
715
|
|
|
716
|
-
### twig.filterElements(elements, condition) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
716
|
+
### twig.filterElements(elements, [condition]) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
717
717
|
Common function to filter Twig elements from array
|
|
718
718
|
|
|
719
719
|
**Kind**: instance method of [<code>Twig</code>](#Twig)
|
|
@@ -722,11 +722,11 @@ Common function to filter Twig elements from array
|
|
|
722
722
|
| Param | Type | Description |
|
|
723
723
|
| --- | --- | --- |
|
|
724
724
|
| elements | [<code>Twig</code>](#Twig) \| [<code>Array.<Twig></code>](#Twig) | Array of elements you like to filter or a single element |
|
|
725
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
725
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
726
726
|
|
|
727
727
|
<a name="Twig+testElement"></a>
|
|
728
728
|
|
|
729
|
-
### twig.testElement(element, condition) ⇒ <code>boolean</code>
|
|
729
|
+
### twig.testElement(element, [condition]) ⇒ <code>boolean</code>
|
|
730
730
|
Common function to filter Twig element
|
|
731
731
|
|
|
732
732
|
**Kind**: instance method of [<code>Twig</code>](#Twig)
|
|
@@ -735,7 +735,7 @@ Common function to filter Twig element
|
|
|
735
735
|
| Param | Type | Description |
|
|
736
736
|
| --- | --- | --- |
|
|
737
737
|
| element | [<code>Twig</code>](#Twig) | Element you like to filter |
|
|
738
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
738
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
739
739
|
|
|
740
740
|
<a name="Twig"></a>
|
|
741
741
|
|
|
@@ -744,7 +744,7 @@ Common function to filter Twig element
|
|
|
744
744
|
|
|
745
745
|
* [Twig](#Twig)
|
|
746
746
|
* [new Twig()](#new_Twig_new)
|
|
747
|
-
* [new Twig(name, parent, attributes, index)](#new_Twig_new)
|
|
747
|
+
* [new Twig(name, [parent], [attributes], [index])](#new_Twig_new)
|
|
748
748
|
* [.attributes](#Twig+attributes) ℗
|
|
749
749
|
* [.text](#Twig+text) ℗
|
|
750
750
|
* [.name](#Twig+name) ℗
|
|
@@ -797,8 +797,8 @@ Common function to filter Twig element
|
|
|
797
797
|
* [.addElement](#Twig+addElement) ⇒ [<code>Twig</code>](#Twig)
|
|
798
798
|
* [.delete](#Twig+delete)
|
|
799
799
|
* [.setRoot(name)](#Twig+setRoot) ℗
|
|
800
|
-
* [.filterElements(elements, condition)](#Twig+filterElements) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
801
|
-
* [.testElement(element, condition)](#Twig+testElement) ⇒ <code>boolean</code>
|
|
800
|
+
* [.filterElements(elements, [condition])](#Twig+filterElements) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
801
|
+
* [.testElement(element, [condition])](#Twig+testElement) ⇒ <code>boolean</code>
|
|
802
802
|
|
|
803
803
|
<a name="new_Twig_new"></a>
|
|
804
804
|
|
|
@@ -807,16 +807,16 @@ Generic class modeling a XML Node
|
|
|
807
807
|
|
|
808
808
|
<a name="new_Twig_new"></a>
|
|
809
809
|
|
|
810
|
-
### new Twig(name, parent, attributes, index)
|
|
810
|
+
### new Twig(name, [parent], [attributes], [index])
|
|
811
811
|
Create a new Twig object
|
|
812
812
|
|
|
813
813
|
|
|
814
814
|
| Param | Type | Description |
|
|
815
815
|
| --- | --- | --- |
|
|
816
816
|
| name | <code>string</code> | The name of the XML element |
|
|
817
|
-
| parent | [<code>Twig</code>](#Twig) | The parent object |
|
|
818
|
-
| attributes | <code>object</code> | Attribute object |
|
|
819
|
-
| index | <code>string</code> \| <code>number</code> | Position name 'first', 'last' or the position in the current `children` array.<br>Defaults to 'last' |
|
|
817
|
+
| [parent] | [<code>Twig</code>](#Twig) | The parent object |
|
|
818
|
+
| [attributes] | <code>object</code> | Attribute object |
|
|
819
|
+
| [index] | <code>string</code> \| <code>number</code> | Position name 'first', 'last' or the position in the current `children` array.<br>Defaults to 'last' |
|
|
820
820
|
|
|
821
821
|
<a name="Twig+attributes"></a>
|
|
822
822
|
|
|
@@ -899,7 +899,7 @@ Purges up to the elt element. This allows you to keep part of the tree in memory
|
|
|
899
899
|
|
|
900
900
|
| Param | Type | Description |
|
|
901
901
|
| --- | --- | --- |
|
|
902
|
-
| elt | [<code>Twig</code>](#Twig) | Up to this element the tree will be purged. The `elt` object itself is not purged.<br> If `undefined` then the current element is purged (i.e. `purge()`) |
|
|
902
|
+
| [elt] | [<code>Twig</code>](#Twig) | Up to this element the tree will be purged. The `elt` object itself is not purged.<br> If `undefined` then the current element is purged (i.e. `purge()`) |
|
|
903
903
|
|
|
904
904
|
<a name="Twig+escapeEntity"></a>
|
|
905
905
|
|
|
@@ -1013,7 +1013,7 @@ Internal recursive function used by `writer()`
|
|
|
1013
1013
|
| Param | Type | Description |
|
|
1014
1014
|
| --- | --- | --- |
|
|
1015
1015
|
| xw | <code>XMLWriter</code> | The writer object |
|
|
1016
|
-
|
|
|
1016
|
+
| childArray | [<code>Array.<Twig></code>](#Twig) | Array of child elements |
|
|
1017
1017
|
|
|
1018
1018
|
<a name="Twig+writer"></a>
|
|
1019
1019
|
|
|
@@ -1036,7 +1036,7 @@ Returns attribute value or `null` if not found.<br>
|
|
|
1036
1036
|
|
|
1037
1037
|
| Param | Type | Description |
|
|
1038
1038
|
| --- | --- | --- |
|
|
1039
|
-
| condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attribute |
|
|
1039
|
+
| [condition] | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attribute |
|
|
1040
1040
|
|
|
1041
1041
|
<a name="Twig+attributes"></a>
|
|
1042
1042
|
|
|
@@ -1067,8 +1067,8 @@ Retrieve or update XML attribute. For update, the condition must be a string, i.
|
|
|
1067
1067
|
|
|
1068
1068
|
| Param | Type | Description |
|
|
1069
1069
|
| --- | --- | --- |
|
|
1070
|
-
| condition | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attributes |
|
|
1071
|
-
| value | <code>string</code> \| <code>number</code> \| <code>bigint</code> \| <code>boolean</code> | New value of the attribute.<br>If `undefined` then existing attributes is returned. |
|
|
1070
|
+
| [condition] | [<code>AttributeCondition</code>](#AttributeCondition) | Optional condition to select attributes |
|
|
1071
|
+
| [value] | <code>string</code> \| <code>number</code> \| <code>bigint</code> \| <code>boolean</code> | New value of the attribute.<br>If `undefined` then existing attributes is returned. |
|
|
1072
1072
|
|
|
1073
1073
|
**Example**
|
|
1074
1074
|
```js
|
|
@@ -1113,7 +1113,7 @@ All children, optionally matching `condition` of the current element or empty ar
|
|
|
1113
1113
|
|
|
1114
1114
|
| Param | Type | Description |
|
|
1115
1115
|
| --- | --- | --- |
|
|
1116
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1116
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1117
1117
|
|
|
1118
1118
|
<a name="Twig+next"></a>
|
|
1119
1119
|
|
|
@@ -1126,7 +1126,7 @@ Returns the next matching element.
|
|
|
1126
1126
|
|
|
1127
1127
|
| Param | Type | Description |
|
|
1128
1128
|
| --- | --- | --- |
|
|
1129
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1129
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1130
1130
|
|
|
1131
1131
|
<a name="Twig+previous"></a>
|
|
1132
1132
|
|
|
@@ -1139,7 +1139,7 @@ Returns the previous matching element.
|
|
|
1139
1139
|
|
|
1140
1140
|
| Param | Type | Description |
|
|
1141
1141
|
| --- | --- | --- |
|
|
1142
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1142
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1143
1143
|
|
|
1144
1144
|
<a name="Twig+first"></a>
|
|
1145
1145
|
|
|
@@ -1151,7 +1151,7 @@ Returns the first matching element. This is usually the root element
|
|
|
1151
1151
|
|
|
1152
1152
|
| Param | Type | Description |
|
|
1153
1153
|
| --- | --- | --- |
|
|
1154
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1154
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1155
1155
|
|
|
1156
1156
|
<a name="Twig+last"></a>
|
|
1157
1157
|
|
|
@@ -1163,7 +1163,7 @@ Returns the last matching element.
|
|
|
1163
1163
|
|
|
1164
1164
|
| Param | Type | Description |
|
|
1165
1165
|
| --- | --- | --- |
|
|
1166
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1166
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1167
1167
|
|
|
1168
1168
|
<a name="Twig+isFirstChild"></a>
|
|
1169
1169
|
|
|
@@ -1189,7 +1189,7 @@ Returns descendants (children, grandchildren, etc.) of the current element
|
|
|
1189
1189
|
|
|
1190
1190
|
| Param | Type | Description |
|
|
1191
1191
|
| --- | --- | --- |
|
|
1192
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1192
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1193
1193
|
|
|
1194
1194
|
<a name="Twig+descendantOrSelf"></a>
|
|
1195
1195
|
|
|
@@ -1201,7 +1201,7 @@ Returns descendants (children, grandchildren, etc.) of the current element and t
|
|
|
1201
1201
|
|
|
1202
1202
|
| Param | Type | Description |
|
|
1203
1203
|
| --- | --- | --- |
|
|
1204
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1204
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1205
1205
|
|
|
1206
1206
|
<a name="Twig+ancestor"></a>
|
|
1207
1207
|
|
|
@@ -1213,7 +1213,7 @@ Returns ancestors (parent, grandparent, etc.) of the current element
|
|
|
1213
1213
|
|
|
1214
1214
|
| Param | Type | Description |
|
|
1215
1215
|
| --- | --- | --- |
|
|
1216
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1216
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1217
1217
|
|
|
1218
1218
|
<a name="Twig+ancestorOrSelf"></a>
|
|
1219
1219
|
|
|
@@ -1225,7 +1225,7 @@ Returns ancestors (parent, grandparent, etc.) of the current element and the cu
|
|
|
1225
1225
|
|
|
1226
1226
|
| Param | Type | Description |
|
|
1227
1227
|
| --- | --- | --- |
|
|
1228
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1228
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1229
1229
|
|
|
1230
1230
|
<a name="Twig+sibling"></a>
|
|
1231
1231
|
|
|
@@ -1237,7 +1237,7 @@ Returns all sibling element of the current element
|
|
|
1237
1237
|
|
|
1238
1238
|
| Param | Type | Description |
|
|
1239
1239
|
| --- | --- | --- |
|
|
1240
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1240
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1241
1241
|
|
|
1242
1242
|
<a name="Twig+siblingOrSelf"></a>
|
|
1243
1243
|
|
|
@@ -1249,7 +1249,7 @@ Returns all sibling element of the current element and the current element itsel
|
|
|
1249
1249
|
|
|
1250
1250
|
| Param | Type | Description |
|
|
1251
1251
|
| --- | --- | --- |
|
|
1252
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1252
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1253
1253
|
|
|
1254
1254
|
<a name="Twig+followingSibling"></a>
|
|
1255
1255
|
|
|
@@ -1261,7 +1261,7 @@ Returns all following sibling element of the current element
|
|
|
1261
1261
|
|
|
1262
1262
|
| Param | Type | Description |
|
|
1263
1263
|
| --- | --- | --- |
|
|
1264
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1264
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1265
1265
|
|
|
1266
1266
|
<a name="Twig+precedingSibling"></a>
|
|
1267
1267
|
|
|
@@ -1273,7 +1273,7 @@ Returns all preceding sibling element of the current element
|
|
|
1273
1273
|
|
|
1274
1274
|
| Param | Type | Description |
|
|
1275
1275
|
| --- | --- | --- |
|
|
1276
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1276
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1277
1277
|
|
|
1278
1278
|
<a name="Twig+nextSibling"></a>
|
|
1279
1279
|
|
|
@@ -1285,7 +1285,7 @@ Returns next sibling element of the current element
|
|
|
1285
1285
|
|
|
1286
1286
|
| Param | Type | Description |
|
|
1287
1287
|
| --- | --- | --- |
|
|
1288
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1288
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1289
1289
|
|
|
1290
1290
|
<a name="Twig+prevSibling"></a>
|
|
1291
1291
|
|
|
@@ -1297,7 +1297,7 @@ Returns previous sibling element of the current element
|
|
|
1297
1297
|
|
|
1298
1298
|
| Param | Type | Description |
|
|
1299
1299
|
| --- | --- | --- |
|
|
1300
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1300
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | Optional condition |
|
|
1301
1301
|
|
|
1302
1302
|
<a name="Twig+find"></a>
|
|
1303
1303
|
|
|
@@ -1322,9 +1322,9 @@ Add a new element in the current element
|
|
|
1322
1322
|
| Param | Type | Description |
|
|
1323
1323
|
| --- | --- | --- |
|
|
1324
1324
|
| name | <code>string</code> | The tag name |
|
|
1325
|
-
| text | <code>string</code> | Text of the element |
|
|
1326
|
-
| attributes | <code>object</code> | Element attributes |
|
|
1327
|
-
| position | <code>name</code> \| <code>number</code> | Position name 'first', 'last' or the position in the `children` |
|
|
1325
|
+
| [text] | <code>string</code> | Text of the element |
|
|
1326
|
+
| [attributes] | <code>object</code> | Element attributes |
|
|
1327
|
+
| [position] | <code>name</code> \| <code>number</code> | Position name 'first', 'last' or the position in the `children` |
|
|
1328
1328
|
|
|
1329
1329
|
<a name="Twig+delete"></a>
|
|
1330
1330
|
|
|
@@ -1346,7 +1346,7 @@ Sets the name of root element. In some cases the root is created before the XML-
|
|
|
1346
1346
|
|
|
1347
1347
|
<a name="Twig+filterElements"></a>
|
|
1348
1348
|
|
|
1349
|
-
### twig.filterElements(elements, condition) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
1349
|
+
### twig.filterElements(elements, [condition]) ⇒ [<code>Array.<Twig></code>](#Twig)
|
|
1350
1350
|
Common function to filter Twig elements from array
|
|
1351
1351
|
|
|
1352
1352
|
**Kind**: instance method of [<code>Twig</code>](#Twig)
|
|
@@ -1355,11 +1355,11 @@ Common function to filter Twig elements from array
|
|
|
1355
1355
|
| Param | Type | Description |
|
|
1356
1356
|
| --- | --- | --- |
|
|
1357
1357
|
| elements | [<code>Twig</code>](#Twig) \| [<code>Array.<Twig></code>](#Twig) | Array of elements you like to filter or a single element |
|
|
1358
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
1358
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
1359
1359
|
|
|
1360
1360
|
<a name="Twig+testElement"></a>
|
|
1361
1361
|
|
|
1362
|
-
### twig.testElement(element, condition) ⇒ <code>boolean</code>
|
|
1362
|
+
### twig.testElement(element, [condition]) ⇒ <code>boolean</code>
|
|
1363
1363
|
Common function to filter Twig element
|
|
1364
1364
|
|
|
1365
1365
|
**Kind**: instance method of [<code>Twig</code>](#Twig)
|
|
@@ -1368,7 +1368,7 @@ Common function to filter Twig element
|
|
|
1368
1368
|
| Param | Type | Description |
|
|
1369
1369
|
| --- | --- | --- |
|
|
1370
1370
|
| element | [<code>Twig</code>](#Twig) | Element you like to filter |
|
|
1371
|
-
| condition | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
1371
|
+
| [condition] | [<code>ElementCondition</code>](#ElementCondition) | The filter condition |
|
|
1372
1372
|
|
|
1373
1373
|
<a name="NotImplementedYet"></a>
|
|
1374
1374
|
|
|
@@ -1443,7 +1443,7 @@ Generic error for unsupported data types
|
|
|
1443
1443
|
**Kind**: global constant
|
|
1444
1444
|
<a name="createParser"></a>
|
|
1445
1445
|
|
|
1446
|
-
## createParser(handler, options)
|
|
1446
|
+
## createParser(handler, [options])
|
|
1447
1447
|
Create a new Twig parser
|
|
1448
1448
|
|
|
1449
1449
|
**Kind**: global function
|
|
@@ -1455,7 +1455,7 @@ Create a new Twig parser
|
|
|
1455
1455
|
| Param | Type | Description |
|
|
1456
1456
|
| --- | --- | --- |
|
|
1457
1457
|
| handler | [<code>TwigHandler</code>](#TwigHandler) \| [<code>Array.<TwigHandler></code>](#TwigHandler) | Object or array of element specification and function to handle elements |
|
|
1458
|
-
| options | [<code>ParserOptions</code>](#ParserOptions) | Object of optional options |
|
|
1458
|
+
| [options] | [<code>ParserOptions</code>](#ParserOptions) | Object of optional options |
|
|
1459
1459
|
|
|
1460
1460
|
<a name="ParserOptions"></a>
|
|
1461
1461
|
|
|
@@ -1464,15 +1464,16 @@ Optional settings for the Twig parser
|
|
|
1464
1464
|
|
|
1465
1465
|
**Kind**: global typedef
|
|
1466
1466
|
**Default**: <code>{ method: 'sax', encoding: 'UTF-8', xmlns: false, trim: true, resumeAfterError: false, partial: false }</code>
|
|
1467
|
+
**Properties**
|
|
1467
1468
|
|
|
1468
|
-
|
|
|
1469
|
+
| Name | Type | Description |
|
|
1469
1470
|
| --- | --- | --- |
|
|
1470
|
-
| method | <code>string</code> | The underlying parser. Either `'sax'` or `'expat'`. |
|
|
1471
|
-
| encoding | <code>string</code> | Encoding of the XML File. Applies only to `expat` parser. |
|
|
1472
|
-
| xmlns | <code>boolean</code> | If `true`, then namespaces are accessible by `namespace` property. |
|
|
1473
|
-
| trim | <code>boolean</code> | If `true`, then turn any whitespace into a single space. Text and comments are trimmed. |
|
|
1474
|
-
| resumeAfterError | <code>boolean</code> | If `true` then parser continues reading after an error. Otherwise it throws exception. |
|
|
1475
|
-
| partial | <code>boolean</code> | It `true` then unhandled elements are purged. |
|
|
1471
|
+
| [method] | <code>string</code> | The underlying parser. Either `'sax'` or `'expat'`. |
|
|
1472
|
+
| [encoding] | <code>string</code> | Encoding of the XML File. Applies only to `expat` parser. |
|
|
1473
|
+
| [xmlns] | <code>boolean</code> | If `true`, then namespaces are accessible by `namespace` property. |
|
|
1474
|
+
| [trim] | <code>boolean</code> | If `true`, then turn any whitespace into a single space. Text and comments are trimmed. |
|
|
1475
|
+
| [resumeAfterError] | <code>boolean</code> | If `true` then parser continues reading after an error. Otherwise it throws exception. |
|
|
1476
|
+
| [partial] | <code>boolean</code> | It `true` then unhandled elements are purged. |
|
|
1476
1477
|
|
|
1477
1478
|
**Example**
|
|
1478
1479
|
```js
|
|
@@ -1484,8 +1485,9 @@ Optional settings for the Twig parser
|
|
|
1484
1485
|
Reference to handler functions for Twig objects.<br>
|
|
1485
1486
|
|
|
1486
1487
|
**Kind**: global typedef
|
|
1488
|
+
**Properties**
|
|
1487
1489
|
|
|
1488
|
-
|
|
|
1490
|
+
| Name | Type | Description |
|
|
1489
1491
|
| --- | --- | --- |
|
|
1490
1492
|
| tag | [<code>HandlerCondition</code>](#HandlerCondition) | Element specification |
|
|
1491
1493
|
| function | [<code>HandlerFunction</code>](#HandlerFunction) | Definition of handler function, either anonymous or explicit function |
|
|
@@ -1493,7 +1495,7 @@ Reference to handler functions for Twig objects.<br>
|
|
|
1493
1495
|
|
|
1494
1496
|
<a name="HandlerCondition"></a>
|
|
1495
1497
|
|
|
1496
|
-
## HandlerCondition : <code>string</code> \| <code>RegExp</code> \| [<code>HandlerConditionFilter</code>](#HandlerConditionFilter) \| <code>RootHandler</code> \| <code>AnyHandler</code>
|
|
1498
|
+
## HandlerCondition : <code>string</code> \| <code>RegExp</code> \| [<code>HandlerConditionFilter</code>](#HandlerConditionFilter) \| <code>RootHandler</code> \| <code>AnyHandler</code> \| <code>undefined</code>
|
|
1497
1499
|
Condition to specify when handler shall be called<br>
|
|
1498
|
-
If `undefined`, then all elements are returned.<br>
|
|
1499
|
-
If `string` then the element name must be equal to the string
|
|
1500
|
-
If `RegExp` then the element name must match the Regular Expression
|
|
1501
|
-
If [HandlerConditionFilter](#HandlerConditionFilter) then function must return `true`
|
|
1502
|
-
Use `Twig.Root` to call the handler on root element, i.e. when the end of document is reached
|
|
1503
|
-
Use `Twig.Any` to call the handler on every element
|
|
1504
1500
|
|
|
1505
1501
|
**Kind**: global typedef
|
|
@@ -1503,17 +1505,19 @@ Condition to specify when handler shall be called<br>
|
|
|
1503
|
-
If `undefined`, then al
|
|
1504
1505
|
Handler function for Twig objects, i.e. the way you like to use the XML element.
|
|
1505
1506
|
|
|
1506
1507
|
**Kind**: global typedef
|
|
1508
|
+
**Properties**
|
|
1507
1509
|
|
|
1508
|
-
|
|
|
1510
|
+
| Name | Type | Description |
|
|
1509
1511
|
| --- | --- | --- |
|
|
1510
1512
|
| elt | [<code>Twig</code>](#Twig) | The current Twig element on which the function was called. |
|
|
1511
1513
|
|
|
1512
1514
|
<a name="HandlerConditionFilter"></a>
|
|
1513
1515
|
|
|
1514
|
-
## HandlerConditionFilter
|
|
1516
|
+
## HandlerConditionFilter ⇒ <code>boolean</code>
|
|
1515
1517
|
Custom filter function to specify when handler shall be called
|
|
1516
1518
|
|
|
1517
1519
|
**Kind**: global typedef
|
|
1520
|
+
**Returns**: <code>boolean</code> - If the function returns `true`, then it is included in the filter
|
|
1518
1521
|
|
|
1519
1522
|
| Param | Type | Description |
|
|
1520
1523
|
| --- | --- | --- |
|
|
@@ -1521,16 +1525,17 @@ Custom filter function to specify when handler shall be called
|
|
|
1521
1525
|
|
|
1522
1526
|
<a name="ElementCondition"></a>
|
|
1523
1527
|
|
|
1524
|
-
## ElementCondition : <code>string</code> \| <code>RegExp</code> \| [<code>ElementConditionFilter</code>](#ElementConditionFilter) \| [<code>Twig</code>](#Twig)
|
|
1528
|
+
## ElementCondition : <code>string</code> \| <code>RegExp</code> \| [<code>ElementConditionFilter</code>](#ElementConditionFilter) \| [<code>Twig</code>](#Twig) \| <code>undefined</code>
|
|
1525
1529
|
Optional condition to get elements<br>
|
|
1526
|
-
If `undefined`, then all elements are returned.<br>
|
|
1527
|
-
If `string` then the element name must be equal to the string
|
|
1528
|
-
If `RegExp` then the element name must match the Regular Expression
|
|
1529
|
-
If [ElementConditionFilter](#ElementConditionFilter) then function must return `true`
|
|
1530
|
-
Use [Twig](#Twig) object to find a specific element
|
|
1531
1530
|
|
|
1532
1531
|
**Kind**: global typedef
|
|
1533
1532
|
<a name="ElementConditionFilter"></a>
|
|
1534
1533
|
|
|
1535
|
-
## ElementConditionFilter
|
|
1534
|
+
## ElementConditionFilter ⇒ <code>boolean</code>
|
|
1536
1535
|
Custom filter function to select desired elements
|
|
1537
1536
|
|
|
1538
1537
|
**Kind**: global typedef
|
|
1538
|
+
**Returns**: <code>boolean</code> - If the function returns `true`, then it is included in the filter
|
|
1539
1539
|
|
|
1540
1540
|
| Param | Type | Description |
|
|
1541
1541
|
| --- | --- | --- |
|