1 |
|
2 | import { Writable } from 'stream';
|
3 |
|
4 | export = xmlbuilder;
|
5 |
|
6 | /**
|
7 | * Type definitions for [xmlbuilder](https://github.com/oozcitak/xmlbuilder-js)
|
8 | *
|
9 | * Original definitions on [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) by:
|
10 | * - Wallymathieu <https://github.com/wallymathieu>
|
11 | * - GaikwadPratik <https://github.com/GaikwadPratik>
|
12 | */
|
13 | declare namespace xmlbuilder {
|
14 | /**
|
15 | * Creates a new XML document and returns the root element node.
|
16 | *
|
17 | * @param nameOrObject - name of the root element or a JS object to be
|
18 | * converted to an XML tree
|
19 | * @param xmldecOrOptions - XML declaration or create options
|
20 | * @param doctypeOrOptions - Doctype declaration or create options
|
21 | * @param options - create options
|
22 | */
|
23 | function create(nameOrObject: string | { [name: string]: Object },
|
24 | xmldecOrOptions?: CreateOptions, doctypeOrOptions?: CreateOptions,
|
25 | options?: CreateOptions): XMLElement;
|
26 |
|
27 | /**
|
28 | * Defines the options used while creating an XML document with the `create`
|
29 | * function.
|
30 | */
|
31 | interface CreateOptions {
|
32 | /**
|
33 | * A version number string, e.g. `1.0`
|
34 | */
|
35 | version?: string;
|
36 | /**
|
37 | * Encoding declaration, e.g. `UTF-8`
|
38 | */
|
39 | encoding?: string;
|
40 | /**
|
41 | * Standalone document declaration: `true` or `false`
|
42 | */
|
43 | standalone?: boolean;
|
44 |
|
45 | /**
|
46 | * Public identifier of the DTD
|
47 | */
|
48 | pubID?: string;
|
49 | /**
|
50 | * System identifier of the DTD
|
51 | */
|
52 | sysID?: string;
|
53 |
|
54 | /**
|
55 | * Whether XML declaration and doctype will be included
|
56 | */
|
57 | headless?: boolean;
|
58 | /**
|
59 | * Whether nodes with `null` values will be kept or ignored
|
60 | */
|
61 | keepNullNodes?: boolean;
|
62 | /**
|
63 | * Whether attributes with `null` values will be kept or ignored
|
64 | */
|
65 | keepNullAttributes?: boolean;
|
66 | /**
|
67 | * Whether decorator strings will be ignored when converting JS
|
68 | * objects
|
69 | */
|
70 | ignoreDecorators?: boolean;
|
71 | /**
|
72 | * Whether array items are created as separate nodes when passed
|
73 | * as an object value
|
74 | */
|
75 | separateArrayItems?: boolean;
|
76 | /**
|
77 | * Whether existing html entities are encoded
|
78 | */
|
79 | noDoubleEncoding?: boolean;
|
80 | /**
|
81 | * Whether values will be validated and escaped or returned as is
|
82 | */
|
83 | noValidation?: boolean;
|
84 | /**
|
85 | * A character to replace invalid characters in all values. This also
|
86 | * disables character validation.
|
87 | */
|
88 | invalidCharReplacement?: string;
|
89 | /**
|
90 | * A set of functions to use for converting values to strings
|
91 | */
|
92 | stringify?: XMLStringifier;
|
93 | /**
|
94 | * The default XML writer to use for converting nodes to string.
|
95 | * If the default writer is not set, the built-in `XMLStringWriter`
|
96 | * will be used instead.
|
97 | */
|
98 | writer?: XMLWriter;
|
99 | }
|
100 |
|
101 | /**
|
102 | * Defines the functions used for converting values to strings.
|
103 | */
|
104 | interface XMLStringifier {
|
105 | /**
|
106 | * Converts an element or attribute name to string
|
107 | */
|
108 | name?: (v: any) => string;
|
109 | /**
|
110 | * Converts the contents of a text node to string
|
111 | */
|
112 | text?: (v: any) => string;
|
113 | /**
|
114 | * Converts the contents of a CDATA node to string
|
115 | */
|
116 | cdata?: (v: any) => string;
|
117 | /**
|
118 | * Converts the contents of a comment node to string
|
119 | */
|
120 | comment?: (v: any) => string;
|
121 | /**
|
122 | * Converts the contents of a raw text node to string
|
123 | */
|
124 | raw?: (v: any) => string;
|
125 | /**
|
126 | * Converts attribute value to string
|
127 | */
|
128 | attValue?: (v: any) => string;
|
129 | /**
|
130 | * Converts processing instruction target to string
|
131 | */
|
132 | insTarget?: (v: any) => string;
|
133 | /**
|
134 | * Converts processing instruction value to string
|
135 | */
|
136 | insValue?: (v: any) => string;
|
137 | /**
|
138 | * Converts XML version to string
|
139 | */
|
140 | xmlVersion?: (v: any) => string;
|
141 | /**
|
142 | * Converts XML encoding to string
|
143 | */
|
144 | xmlEncoding?: (v: any) => string;
|
145 | /**
|
146 | * Converts standalone document declaration to string
|
147 | */
|
148 | xmlStandalone?: (v: any) => string;
|
149 | /**
|
150 | * Converts DocType public identifier to string
|
151 | */
|
152 | dtdPubID?: (v: any) => string;
|
153 | /**
|
154 | * Converts DocType system identifier to string
|
155 | */
|
156 | dtdSysID?: (v: any) => string;
|
157 | /**
|
158 | * Converts `!ELEMENT` node content inside Doctype to string
|
159 | */
|
160 | dtdElementValue?: (v: any) => string;
|
161 | /**
|
162 | * Converts `!ATTLIST` node type inside DocType to string
|
163 | */
|
164 | dtdAttType?: (v: any) => string;
|
165 | /**
|
166 | * Converts `!ATTLIST` node default value inside DocType to string
|
167 | */
|
168 | dtdAttDefault?: (v: any) => string;
|
169 | /**
|
170 | * Converts `!ENTITY` node content inside Doctype to string
|
171 | */
|
172 | dtdEntityValue?: (v: any) => string;
|
173 | /**
|
174 | * Converts `!NOTATION` node content inside Doctype to string
|
175 | */
|
176 | dtdNData?: (v: any) => string;
|
177 |
|
178 | /**
|
179 | * When prepended to a JS object key, converts the key-value pair
|
180 | * to an attribute.
|
181 | */
|
182 | convertAttKey?: string;
|
183 | /**
|
184 | * When prepended to a JS object key, converts the key-value pair
|
185 | * to a processing instruction node.
|
186 | */
|
187 | convertPIKey?: string;
|
188 | /**
|
189 | * When prepended to a JS object key, converts its value to a text node.
|
190 | *
|
191 | * _Note:_ Since JS objects cannot contain duplicate keys, multiple text
|
192 | * nodes can be created by adding some unique text after each object
|
193 | * key. For example: `{ '#text1': 'some text', '#text2': 'more text' };`
|
194 | */
|
195 | convertTextKey?: string;
|
196 | /**
|
197 | * When prepended to a JS object key, converts its value to a CDATA
|
198 | * node.
|
199 | */
|
200 | convertCDataKey?: string;
|
201 | /**
|
202 | * When prepended to a JS object key, converts its value to a
|
203 | * comment node.
|
204 | */
|
205 | convertCommentKey?: string;
|
206 | /**
|
207 | * When prepended to a JS object key, converts its value to a raw
|
208 | * text node.
|
209 | */
|
210 | convertRawKey?: string;
|
211 |
|
212 | /**
|
213 | * Escapes special characters in text.
|
214 | */
|
215 | textEscape?: (v: string) => string;
|
216 |
|
217 | /**
|
218 | * Escapes special characters in attribute values.
|
219 | */
|
220 | attEscape?: (v: string) => string;
|
221 | }
|
222 |
|
223 | /**
|
224 | * Represents a writer which outputs an XML document.
|
225 | */
|
226 | interface XMLWriter {
|
227 | /**
|
228 | * Writes the indentation string for the given level.
|
229 | *
|
230 | * @param node - current node
|
231 | * @param options - writer options and state information
|
232 | * @param level - current depth of the XML tree
|
233 | */
|
234 | indent?: (node: XMLNode, options: WriterOptions, level: number) => any
|
235 |
|
236 | /**
|
237 | * Writes the newline string.
|
238 | *
|
239 | * @param node - current node
|
240 | * @param options - writer options and state information
|
241 | * @param level - current depth of the XML tree
|
242 | */
|
243 | endline?: (node: XMLNode, options: WriterOptions, level: number) => any
|
244 |
|
245 | /**
|
246 | * Writes an attribute.
|
247 | *
|
248 | * @param att - current attribute
|
249 | * @param options - writer options and state information
|
250 | * @param level - current depth of the XML tree
|
251 | */
|
252 | attribute?: (att: XMLAttribute, options: WriterOptions,
|
253 | level: number) => any
|
254 |
|
255 | /**
|
256 | * Writes a CDATA node.
|
257 | *
|
258 | * @param node - current node
|
259 | * @param options - writer options and state information
|
260 | * @param level - current depth of the XML tree
|
261 | */
|
262 | cdata?: (node: XMLCData, options: WriterOptions, level: number) => any
|
263 |
|
264 | /**
|
265 | * Writes a comment node.
|
266 | *
|
267 | * @param node - current node
|
268 | * @param options - writer options and state information
|
269 | * @param level - current depth of the XML tree
|
270 | */
|
271 | comment?: (node: XMLComment, options: WriterOptions,
|
272 | level: number) => any
|
273 |
|
274 | /**
|
275 | * Writes the XML declaration (e.g. `<?xml version="1.0"?>`).
|
276 | *
|
277 | * @param node - XML declaration node
|
278 | * @param options - writer options and state information
|
279 | * @param level - current depth of the XML tree
|
280 | */
|
281 | declaration?: (node: XMLDeclaration, options: WriterOptions,
|
282 | level: number) => any
|
283 |
|
284 | /**
|
285 | * Writes the DocType node and its children.
|
286 | *
|
287 | * _Note:_ Be careful when overriding this function as this function
|
288 | * is also responsible for writing the internal subset of the DTD.
|
289 | *
|
290 | * @param node - DOCTYPE node
|
291 | * @param options - writer options and state information
|
292 | * @param level - current depth of the XML tree
|
293 | */
|
294 | docType?: (node: XMLDocType, options: WriterOptions,
|
295 | level: number) => any
|
296 |
|
297 | /**
|
298 | * Writes an element node.
|
299 | *
|
300 | * _Note:_ Be careful when overriding this function as this function
|
301 | * is also responsible for writing the element attributes and child
|
302 | * nodes.
|
303 | *
|
304 | *
|
305 | * @param node - current node
|
306 | * @param options - writer options and state information
|
307 | * @param level - current depth of the XML tree
|
308 | */
|
309 | element?: (node: XMLElement, options: WriterOptions,
|
310 | level: number) => any
|
311 |
|
312 | /**
|
313 | * Writes a processing instruction node.
|
314 | *
|
315 | * @param node - current node
|
316 | * @param options - writer options and state information
|
317 | * @param level - current depth of the XML tree
|
318 | */
|
319 | processingInstruction?: (node: XMLProcessingInstruction,
|
320 | options: WriterOptions, level: number) => any
|
321 |
|
322 | /**
|
323 | * Writes a raw text node.
|
324 | *
|
325 | * @param node - current node
|
326 | * @param options - writer options and state information
|
327 | * @param level - current depth of the XML tree
|
328 | */
|
329 | raw?: (node: XMLRaw, options: WriterOptions, level: number) => any
|
330 |
|
331 | /**
|
332 | * Writes a text node.
|
333 | *
|
334 | * @param node - current node
|
335 | * @param options - writer options and state information
|
336 | * @param level - current depth of the XML tree
|
337 | */
|
338 | text?: (node: XMLText, options: WriterOptions, level: number) => any
|
339 |
|
340 | /**
|
341 | * Writes an attribute node (`!ATTLIST`) inside the DTD.
|
342 | *
|
343 | * @param node - current node
|
344 | * @param options - writer options and state information
|
345 | * @param level - current depth of the XML tree
|
346 | */
|
347 | dtdAttList?: (node: XMLDTDAttList, options: WriterOptions,
|
348 | level: number) => any
|
349 |
|
350 | /**
|
351 | * Writes an element node (`!ELEMENT`) inside the DTD.
|
352 | *
|
353 | * @param node - current node
|
354 | * @param options - writer options and state information
|
355 | * @param level - current depth of the XML tree
|
356 | */
|
357 | dtdElement?: (node: XMLDTDElement, options: WriterOptions,
|
358 | level: number) => any
|
359 |
|
360 | /**
|
361 | * Writes an entity node (`!ENTITY`) inside the DTD.
|
362 | *
|
363 | * @param node - current node
|
364 | * @param options - writer options and state information
|
365 | * @param level - current depth of the XML tree
|
366 | */
|
367 | dtdEntity?: (node: XMLDTDEntity, options: WriterOptions,
|
368 | level: number) => any
|
369 |
|
370 | /**
|
371 | * Writes a notation node (`!NOTATION`) inside the DTD.
|
372 | *
|
373 | * @param node - current node
|
374 | * @param options - writer options and state information
|
375 | * @param level - current depth of the XML tree
|
376 | */
|
377 | dtdNotation?: (node: XMLDTDNotation, options: WriterOptions,
|
378 | level: number) => any
|
379 |
|
380 | /**
|
381 | * Called right after starting writing a node. This function does not
|
382 | * produce any output, but can be used to alter the state of the writer.
|
383 | *
|
384 | * @param node - current node
|
385 | * @param options - writer options and state information
|
386 | * @param level - current depth of the XML tree
|
387 | */
|
388 | openNode?: (node: XMLNode, options: WriterOptions,
|
389 | level: number) => void
|
390 |
|
391 | /**
|
392 | * Called right before completing writing a node. This function does not
|
393 | * produce any output, but can be used to alter the state of the writer.
|
394 | *
|
395 | * @param node - current node
|
396 | * @param options - writer options and state information
|
397 | * @param level - current depth of the XML tree
|
398 | */
|
399 | closeNode?: (node: XMLNode, options: WriterOptions,
|
400 | level: number) => void
|
401 |
|
402 | /**
|
403 | * Called right after starting writing an attribute. This function does
|
404 | * not produce any output, but can be used to alter the state of the
|
405 | * writer.
|
406 | *
|
407 | * @param node - current attribute
|
408 | * @param options - writer options and state information
|
409 | * @param level - current depth of the XML tree
|
410 | */
|
411 | openAttribute?: (att: XMLAttribute, options: WriterOptions,
|
412 | level: number) => void
|
413 |
|
414 | /**
|
415 | * Called right before completing writing an attribute. This function
|
416 | * does not produce any output, but can be used to alter the state of
|
417 | * the writer.
|
418 | *
|
419 | * @param node - current attribute
|
420 | * @param options - writer options and state information
|
421 | * @param level - current depth of the XML tree
|
422 | */
|
423 | closeAttribute?: (att: XMLAttribute, options: WriterOptions,
|
424 | level: number) => void
|
425 | }
|
426 |
|
427 | /**
|
428 | * Defines the options passed to the XML writer.
|
429 | */
|
430 | interface WriterOptions {
|
431 | /**
|
432 | * Pretty print the XML tree
|
433 | */
|
434 | pretty?: boolean;
|
435 | /**
|
436 | * Indentation string for pretty printing
|
437 | */
|
438 | indent?: string;
|
439 | /**
|
440 | * Newline string for pretty printing
|
441 | */
|
442 | newline?: string;
|
443 | /**
|
444 | * A fixed number of indents to offset strings
|
445 | */
|
446 | offset?: number;
|
447 | /**
|
448 | * Maximum column width
|
449 | */
|
450 | width?: number;
|
451 | /**
|
452 | * Whether to output closing tags for empty element nodes
|
453 | */
|
454 | allowEmpty?: boolean;
|
455 | /**
|
456 | * Whether to pretty print text nodes
|
457 | */
|
458 | dontPrettyTextNodes?: boolean;
|
459 | /**
|
460 | * A string to insert before closing slash character
|
461 | */
|
462 | spaceBeforeSlash?: string | boolean;
|
463 | /**
|
464 | * User state object that is saved between writer functions
|
465 | */
|
466 | user?: any;
|
467 | /**
|
468 | * The current state of the writer
|
469 | */
|
470 | state?: WriterState;
|
471 | /**
|
472 | * Writer function overrides
|
473 | */
|
474 | writer?: XMLWriter;
|
475 | }
|
476 |
|
477 | /**
|
478 | * Defines the state of the writer.
|
479 | */
|
480 | enum WriterState {
|
481 | /**
|
482 | * Writer state is unknown
|
483 | */
|
484 | None = 0,
|
485 | /**
|
486 | * Writer is at an opening tag, e.g. `<node>`
|
487 | */
|
488 | OpenTag = 1,
|
489 | /**
|
490 | * Writer is inside an element
|
491 | */
|
492 | InsideTag = 2,
|
493 | /**
|
494 | * Writer is at a closing tag, e.g. `</node>`
|
495 | */
|
496 | CloseTag = 3
|
497 | }
|
498 |
|
499 | /**
|
500 | * Creates a new XML document and returns the document node.
|
501 | * This function creates an empty document without the XML prolog or
|
502 | * a root element.
|
503 | *
|
504 | * @param options - create options
|
505 | */
|
506 | function begin(options?: BeginOptions): XMLDocument;
|
507 |
|
508 | /**
|
509 | * Defines the options used while creating an XML document with the `begin`
|
510 | * function.
|
511 | */
|
512 | interface BeginOptions {
|
513 | /**
|
514 | * Whether nodes with null values will be kept or ignored
|
515 | */
|
516 | keepNullNodes?: boolean;
|
517 | /**
|
518 | * Whether attributes with null values will be kept or ignored
|
519 | */
|
520 | keepNullAttributes?: boolean;
|
521 | /**
|
522 | * Whether decorator strings will be ignored when converting JS
|
523 | * objects
|
524 | */
|
525 | ignoreDecorators?: boolean;
|
526 | /**
|
527 | * Whether array items are created as separate nodes when passed
|
528 | * as an object value
|
529 | */
|
530 | separateArrayItems?: boolean;
|
531 | /**
|
532 | * Whether existing html entities are encoded
|
533 | */
|
534 | noDoubleEncoding?: boolean;
|
535 | /**
|
536 | * Whether values will be validated and escaped or returned as is
|
537 | */
|
538 | noValidation?: boolean;
|
539 | /**
|
540 | * A character to replace invalid characters in all values. This also
|
541 | * disables character validation.
|
542 | */
|
543 | invalidCharReplacement?: string;
|
544 | /**
|
545 | * A set of functions to use for converting values to strings
|
546 | */
|
547 | stringify?: XMLStringifier;
|
548 | /**
|
549 | * The default XML writer to use for converting nodes to string.
|
550 | * If the default writer is not set, the built-in XMLStringWriter
|
551 | * will be used instead.
|
552 | */
|
553 | writer?: XMLWriter | WriterOptions;
|
554 | }
|
555 |
|
556 | /**
|
557 | * A function to be called when a chunk of XML is written.
|
558 | *
|
559 | * @param chunk - a chunk of string that was written
|
560 | * @param level - current depth of the XML tree
|
561 | */
|
562 | type OnDataCallback = (chunk: string, level: number) => void;
|
563 |
|
564 | /**
|
565 | * A function to be called when the XML doucment is completed.
|
566 | */
|
567 | type OnEndCallback = () => void;
|
568 |
|
569 | /**
|
570 | * Creates a new XML document in callback mode and returns the document
|
571 | * node.
|
572 | *
|
573 | * @param options - create options
|
574 | * @param onData - the function to be called when a new chunk of XML is
|
575 | * output. The string containing the XML chunk is passed to `onData` as
|
576 | * its first argument and the current depth of the tree is passed as its
|
577 | * second argument.
|
578 | * @param onEnd - the function to be called when the XML document is
|
579 | * completed with `end`. `onEnd` does not receive any arguments.
|
580 | */
|
581 | function begin(options?: BeginOptions | OnDataCallback,
|
582 | onData?: OnDataCallback | OnEndCallback,
|
583 | onEnd?: OnEndCallback): XMLDocumentCB;
|
584 |
|
585 | /**
|
586 | * Creates and returns a default string writer.
|
587 | *
|
588 | * @param options - writer options
|
589 | */
|
590 | function stringWriter(options?: WriterOptions): XMLWriter
|
591 |
|
592 | /**
|
593 | * Creates and returns a default stream writer.
|
594 | *
|
595 | * @param stream - a writeable stream
|
596 | * @param options - writer options
|
597 | */
|
598 | function streamWriter(stream: Writable, options?: WriterOptions): XMLWriter
|
599 |
|
600 | /**
|
601 | * Defines the type of a node in the XML document.
|
602 | */
|
603 | enum NodeType {
|
604 | /**
|
605 | * An element node
|
606 | */
|
607 | Element = 1,
|
608 | /**
|
609 | * An attribute node
|
610 | */
|
611 | Attribute = 2,
|
612 | /**
|
613 | * A text node
|
614 | */
|
615 | Text = 3,
|
616 | /**
|
617 | * A CDATA node
|
618 | */
|
619 | CData = 4,
|
620 | /**
|
621 | * An entity reference node inside DocType
|
622 | */
|
623 | EntityReference = 5,
|
624 | /**
|
625 | * An entity declaration node inside DocType
|
626 | */
|
627 | EntityDeclaration = 6,
|
628 | /**
|
629 | * A processing instruction node
|
630 | */
|
631 | ProcessingInstruction = 7,
|
632 | /**
|
633 | * A comment node
|
634 | */
|
635 | Comment = 8,
|
636 | /**
|
637 | * A document node
|
638 | */
|
639 | Document = 9,
|
640 | /**
|
641 | * A Doctype node
|
642 | */
|
643 | DocType = 10,
|
644 | /**
|
645 | * A document fragment node
|
646 | */
|
647 | DocumentFragment = 11,
|
648 | /**
|
649 | * A notation declaration node inside DocType
|
650 | */
|
651 | NotationDeclaration = 12,
|
652 | /**
|
653 | * An XML declaration node
|
654 | */
|
655 | Declaration = 201,
|
656 | /**
|
657 | * A raw text node
|
658 | */
|
659 | Raw = 202,
|
660 | /**
|
661 | * An attribute declaraiton node inside DocType
|
662 | */
|
663 | AttributeDeclaration = 203,
|
664 | /**
|
665 | * An element declaration node inside DocType
|
666 | */
|
667 | ElementDeclaration = 204
|
668 | }
|
669 |
|
670 | /**
|
671 | * Defines the type of a node in the XML document.
|
672 | */
|
673 | export import nodeType = NodeType;
|
674 |
|
675 | /**
|
676 | * Defines the state of the writer.
|
677 | */
|
678 | export import writerState = WriterState;
|
679 |
|
680 | /**
|
681 | * Defines the settings used when converting the XML document to string.
|
682 | */
|
683 | interface XMLToStringOptions {
|
684 | /**
|
685 | * Pretty print the XML tree
|
686 | */
|
687 | pretty?: boolean;
|
688 | /**
|
689 | * Indentation string for pretty printing
|
690 | */
|
691 | indent?: string;
|
692 | /**
|
693 | * Newline string for pretty printing
|
694 | */
|
695 | newline?: string;
|
696 | /**
|
697 | * A fixed number of indents to offset strings
|
698 | */
|
699 | offset?: number;
|
700 | /**
|
701 | * Maximum column width
|
702 | */
|
703 | width?: number;
|
704 | /**
|
705 | * Whether to output closing tags for empty element nodes
|
706 | */
|
707 | allowEmpty?: boolean;
|
708 | /**
|
709 | * Whether to pretty print text nodes
|
710 | */
|
711 | dontPrettyTextNodes?: boolean;
|
712 | /**
|
713 | * A string to insert before closing slash character
|
714 | */
|
715 | spaceBeforeSlash?: string | boolean;
|
716 | /**
|
717 | * The default XML writer to use for converting nodes to string.
|
718 | * If the default writer is not set, the built-in `XMLStringWriter`
|
719 | * will be used instead.
|
720 | */
|
721 | writer?: XMLWriter;
|
722 | }
|
723 |
|
724 | /**
|
725 | * Represents the XML document.
|
726 | */
|
727 | class XMLDocument extends XMLNode {
|
728 | /**
|
729 | * Converts the node to string
|
730 | *
|
731 | * @param options - conversion options
|
732 | */
|
733 | toString(options?: XMLToStringOptions): string;
|
734 | }
|
735 |
|
736 | /**
|
737 | * Represents an XML attribute.
|
738 | */
|
739 | class XMLAttribute {
|
740 | /**
|
741 | * Type of the node
|
742 | */
|
743 | type: NodeType;
|
744 | /**
|
745 | * Parent element node
|
746 | */
|
747 | parent: XMLElement;
|
748 | /**
|
749 | * Attribute name
|
750 | */
|
751 | name: string;
|
752 | /**
|
753 | * Attribute value
|
754 | */
|
755 | value: string;
|
756 |
|
757 | /**
|
758 | * Creates a clone of this node
|
759 | */
|
760 | clone(): XMLAttribute;
|
761 |
|
762 | /**
|
763 | * Converts the node to string
|
764 | *
|
765 | * @param options - conversion options
|
766 | */
|
767 | toString(options?: XMLToStringOptions): string;
|
768 | }
|
769 |
|
770 | /**
|
771 | * Represents the base class of XML nodes.
|
772 | */
|
773 | abstract class XMLNode {
|
774 | /**
|
775 | * Type of the node
|
776 | */
|
777 | type: NodeType;
|
778 | /**
|
779 | * Parent element node
|
780 | */
|
781 | parent: XMLElement;
|
782 | /**
|
783 | * Child nodes
|
784 | */
|
785 | children: XMLNode[]
|
786 |
|
787 | /**
|
788 | * Creates a new child node and appends it to the list of child nodes.
|
789 | *
|
790 | * _Aliases:_ `ele` and `e`
|
791 | *
|
792 | * @param name - node name or a JS object defining the nodes to insert
|
793 | * @param attributes - node attributes
|
794 | * @param text - node text
|
795 | *
|
796 | * @returns the last top level node created
|
797 | */
|
798 | element(name: any, attributes?: Object, text?: any): XMLElement;
|
799 | ele(name: any, attributes?: Object, text?: any): XMLElement;
|
800 | e(name: any, attributes?: Object, text?: any): XMLElement;
|
801 |
|
802 | /**
|
803 | * Adds or modifies an attribute.
|
804 | *
|
805 | * _Aliases:_ `att`, `a`
|
806 | *
|
807 | * @param name - attribute name
|
808 | * @param value - attribute value
|
809 | *
|
810 | * @returns the parent element node
|
811 | */
|
812 | attribute(name: any, value?: any): XMLElement;
|
813 | att(name: any, value?: any): XMLElement;
|
814 | a(name: any, value?: any): XMLElement;
|
815 |
|
816 | /**
|
817 | * Creates a new sibling node and inserts it before this node.
|
818 | *
|
819 | * @param name - node name or a JS object defining the nodes to insert
|
820 | * @param attributes - node attributes
|
821 | * @param text - node text
|
822 | *
|
823 | * @returns the new node
|
824 | */
|
825 | insertBefore(name: any, attributes?: Object, text?: any): XMLElement;
|
826 | /**
|
827 | * Creates a new sibling node and inserts it after this node.
|
828 | *
|
829 | * @param name - node name or a JS object defining the nodes to insert
|
830 | * @param attributes - node attributes
|
831 | * @param text - node text
|
832 | *
|
833 | * @returns the new node
|
834 | */
|
835 | insertAfter(name: any, attributes?: Object, text?: any): XMLElement;
|
836 | /**
|
837 | * Removes this node from the tree.
|
838 | *
|
839 | * @returns the parent node
|
840 | */
|
841 | remove(): XMLElement;
|
842 |
|
843 | /**
|
844 | * Creates a new element node and appends it to the list of child nodes.
|
845 | *
|
846 | * _Aliases:_ `nod` and `n`
|
847 | *
|
848 | * @param name - element node name
|
849 | * @param attributes - node attributes
|
850 | * @param text - node text
|
851 | *
|
852 | * @returns the node created
|
853 | */
|
854 | node(name: string, attributes?: Object, text?: any): XMLElement;
|
855 | nod(name: string, attributes?: Object, text?: any): XMLElement;
|
856 | n(name: string, attributes?: Object, text?: any): XMLElement;
|
857 |
|
858 | /**
|
859 | * Creates a new text node and appends it to the list of child nodes.
|
860 | *
|
861 | * _Aliases:_ `txt` and `t`
|
862 | *
|
863 | * @param value - node value
|
864 | *
|
865 | * @returns the parent node
|
866 | */
|
867 | text(value: string): XMLElement;
|
868 | txt(value: string): XMLElement;
|
869 | t(value: string): XMLElement;
|
870 |
|
871 | /**
|
872 | * Creates a new CDATA node and appends it to the list of child nodes.
|
873 | *
|
874 | * _Aliases:_ `dat` and `d`
|
875 | *
|
876 | * @param value - node value
|
877 | *
|
878 | * @returns the parent node
|
879 | */
|
880 | cdata(value: string): XMLElement;
|
881 | dat(value: string): XMLElement;
|
882 | d(value: string): XMLElement;
|
883 |
|
884 | /**
|
885 | * Creates a new comment node and appends it to the list of child nodes.
|
886 | *
|
887 | * _Aliases:_ `com` and `c`
|
888 | *
|
889 | * @param value - node value
|
890 | *
|
891 | * @returns the parent node
|
892 | */
|
893 | comment(value: string): XMLElement;
|
894 | com(value: string): XMLElement;
|
895 | c(value: string): XMLElement;
|
896 |
|
897 | /**
|
898 | * Creates a comment node before the current node
|
899 | *
|
900 | * @param value - node value
|
901 | *
|
902 | * @returns the parent node
|
903 | */
|
904 | commentBefore(value: string): XMLElement;
|
905 |
|
906 | /**
|
907 | * Creates a comment node after the current node
|
908 | *
|
909 | * @param value - node value
|
910 | *
|
911 | * @returns the parent node
|
912 | */
|
913 | commentAfter(value: string): XMLElement;
|
914 |
|
915 | /**
|
916 | * Creates a new raw text node and appends it to the list of child
|
917 | * nodes.
|
918 | *
|
919 | * _Alias:_ `r`
|
920 | *
|
921 | * @param value - node value
|
922 | *
|
923 | * @returns the parent node
|
924 | */
|
925 | raw(value: string): XMLElement;
|
926 | r(value: string): XMLElement;
|
927 |
|
928 | /**
|
929 | * Creates a new processing instruction node and appends it to the list
|
930 | * of child nodes.
|
931 | *
|
932 | * _Aliases:_ `ins` and `i`
|
933 | *
|
934 | * @param target - node target
|
935 | * @param value - node value
|
936 | *
|
937 | * @returns the parent node
|
938 | */
|
939 | instruction(target: string, value: any): XMLElement;
|
940 | instruction(array: Array<any>): XMLElement;
|
941 | instruction(obj: Object): XMLElement;
|
942 | ins(target: string, value: any): XMLElement;
|
943 | ins(array: Array<any>): XMLElement;
|
944 | ins(obj: Object): XMLElement;
|
945 | i(target: string, value: any): XMLElement;
|
946 | i(array: Array<any>): XMLElement;
|
947 | i(obj: Object): XMLElement;
|
948 |
|
949 | /**
|
950 | * Creates a processing instruction node before the current node.
|
951 | *
|
952 | * @param target - node target
|
953 | * @param value - node value
|
954 | *
|
955 | * @returns the parent node
|
956 | */
|
957 | instructionBefore(target: string, value: any): XMLElement;
|
958 |
|
959 | /**
|
960 | * Creates a processing instruction node after the current node.
|
961 | *
|
962 | * @param target - node target
|
963 | * @param value - node value
|
964 | *
|
965 | * @returns the parent node
|
966 | */
|
967 | instructionAfter(target: string, value: any): XMLElement;
|
968 |
|
969 | /**
|
970 | * Creates the XML declaration.
|
971 | *
|
972 | * _Alias:_ `dec`
|
973 | *
|
974 | * @param version - version number string, e.g. `1.0`
|
975 | * @param encoding - encoding declaration, e.g. `UTF-8`
|
976 | * @param standalone - standalone document declaration: `true` or `false`
|
977 | *
|
978 | * @returns the root element node
|
979 | */
|
980 | declaration(version?: string |
|
981 | { version?: string, encoding?: string, standalone?: boolean },
|
982 | encoding?: string, standalone?: boolean): XMLElement;
|
983 | dec(version?: string |
|
984 | { version?: string, encoding?: string, standalone?: boolean },
|
985 | encoding?: string, standalone?: boolean): XMLElement;
|
986 |
|
987 | /**
|
988 | * Creates the document type definition.
|
989 | *
|
990 | * _Alias:_ `dtd`
|
991 | *
|
992 | * @param pubID - public identifier of the DTD
|
993 | * @param sysID - system identifier of the DTD
|
994 | *
|
995 | * @returns the DOCTYPE node
|
996 | */
|
997 | doctype(pubID?: string | { pubID?: string, sysID?: string },
|
998 | sysID?: string): XMLDocType;
|
999 | dtd(pubID?: string | { pubID?: string, sysID?: string },
|
1000 | sysID?: string): XMLDocType;
|
1001 |
|
1002 | /**
|
1003 | * Takes the root node of the given XML document and appends it
|
1004 | * to child nodes.
|
1005 | *
|
1006 | * @param doc - the document whose root node to import
|
1007 | *
|
1008 | * @returns the current node
|
1009 | */
|
1010 | importDocument(doc: XMLNode): XMLElement;
|
1011 |
|
1012 | /**
|
1013 | * Converts the XML document to string.
|
1014 | *
|
1015 | * @param options - conversion options
|
1016 | */
|
1017 | end(options?: XMLWriter | XMLToStringOptions): string;
|
1018 |
|
1019 | /**
|
1020 | * Returns the previous sibling node.
|
1021 | */
|
1022 | prev(): XMLNode;
|
1023 | /**
|
1024 | * Returns the next sibling node.
|
1025 | */
|
1026 | next(): XMLNode;
|
1027 | /**
|
1028 | * Returns the parent node.
|
1029 | *
|
1030 | * _Alias:_ `u`
|
1031 | */
|
1032 | up(): XMLElement;
|
1033 | u(): XMLElement;
|
1034 | /**
|
1035 | * Returns the document node.
|
1036 | *
|
1037 | * _Alias:_ `doc`
|
1038 | */
|
1039 | document(): XMLDocument;
|
1040 | doc(): XMLDocument;
|
1041 |
|
1042 | /**
|
1043 | * Returns the root element node.
|
1044 | */
|
1045 | root(): XMLElement;
|
1046 | }
|
1047 |
|
1048 | /**
|
1049 | * Represents the base class of character data nodes.
|
1050 | */
|
1051 | abstract class XMLCharacterData extends XMLNode {
|
1052 | /**
|
1053 | * Node value
|
1054 | */
|
1055 | value: string;
|
1056 | }
|
1057 |
|
1058 | /**
|
1059 | * Represents a CDATA node.
|
1060 | */
|
1061 | class XMLCData extends XMLCharacterData {
|
1062 | /**
|
1063 | * Converts the node to string
|
1064 | *
|
1065 | * @param options - conversion options
|
1066 | */
|
1067 | toString(options?: XMLToStringOptions): string;
|
1068 |
|
1069 | /**
|
1070 | * Creates a clone of this node
|
1071 | */
|
1072 | clone(): XMLCData;
|
1073 | }
|
1074 |
|
1075 | /**
|
1076 | * Represents a comment node.
|
1077 | */
|
1078 | class XMLComment extends XMLCharacterData {
|
1079 | /**
|
1080 | * Converts the node to string
|
1081 | *
|
1082 | * @param options - conversion options
|
1083 | */
|
1084 | toString(options?: XMLToStringOptions): string;
|
1085 |
|
1086 | /**
|
1087 | * Creates a clone of this node
|
1088 | */
|
1089 | clone(): XMLComment;
|
1090 | }
|
1091 |
|
1092 | /**
|
1093 | * Represents a processing instruction node.
|
1094 | */
|
1095 | class XMLProcessingInstruction extends XMLCharacterData {
|
1096 | /** Instruction target
|
1097 | */
|
1098 | target: string;
|
1099 |
|
1100 | /**
|
1101 | * Converts the node to string
|
1102 | *
|
1103 | * @param options - conversion options
|
1104 | */
|
1105 | toString(options?: XMLToStringOptions): string;
|
1106 |
|
1107 | /**
|
1108 | * Creates a clone of this node
|
1109 | */
|
1110 | clone(): XMLProcessingInstruction;
|
1111 | }
|
1112 |
|
1113 | /**
|
1114 | * Represents a raw text node.
|
1115 | */
|
1116 | class XMLRaw extends XMLCharacterData {
|
1117 | /**
|
1118 | * Converts the node to string
|
1119 | *
|
1120 | * @param options - conversion options
|
1121 | */
|
1122 | toString(options?: XMLToStringOptions): string;
|
1123 |
|
1124 | /**
|
1125 | * Creates a clone of this node
|
1126 | */
|
1127 | clone(): XMLRaw;
|
1128 | }
|
1129 |
|
1130 | /**
|
1131 | * Represents a text node.
|
1132 | */
|
1133 | class XMLText extends XMLCharacterData {
|
1134 | /**
|
1135 | * Converts the node to string
|
1136 | *
|
1137 | * @param options - conversion options
|
1138 | */
|
1139 | toString(options?: XMLToStringOptions): string;
|
1140 |
|
1141 | /**
|
1142 | * Creates a clone of this node
|
1143 | */
|
1144 | clone(): XMLText;
|
1145 | }
|
1146 |
|
1147 | /**
|
1148 | * Represents the XML declaration.
|
1149 | */
|
1150 | class XMLDeclaration {
|
1151 | /**
|
1152 | * A version number string, e.g. `1.0`
|
1153 | */
|
1154 | version: string;
|
1155 | /**
|
1156 | * Encoding declaration, e.g. `UTF-8`
|
1157 | */
|
1158 | encoding: string;
|
1159 | /**
|
1160 | * Standalone document declaration: `true` or `false`
|
1161 | */
|
1162 | standalone: boolean;
|
1163 |
|
1164 | /**
|
1165 | * Converts the node to string.
|
1166 | *
|
1167 | * @param options - conversion options
|
1168 | */
|
1169 | toString(options?: XMLToStringOptions): string;
|
1170 | }
|
1171 |
|
1172 | /**
|
1173 | * Represents the document type definition.
|
1174 | */
|
1175 | class XMLDocType {
|
1176 | /**
|
1177 | * Type of the node
|
1178 | */
|
1179 | type: NodeType;
|
1180 | /**
|
1181 | * Parent element node
|
1182 | */
|
1183 | parent: XMLElement;
|
1184 | /**
|
1185 | * Child nodes
|
1186 | */
|
1187 | children: XMLNode[]
|
1188 |
|
1189 | /**
|
1190 | * Public identifier of the DTD
|
1191 | */
|
1192 | pubID: string;
|
1193 | /**
|
1194 | * System identifier of the DTD
|
1195 | */
|
1196 | sysID: string;
|
1197 |
|
1198 | /**
|
1199 | * Creates an element type declaration.
|
1200 | *
|
1201 | * _Alias:_ `ele`
|
1202 | *
|
1203 | * @param name - element name
|
1204 | * @param value - element content (defaults to `#PCDATA`)
|
1205 | *
|
1206 | * @returns the DOCTYPE node
|
1207 | */
|
1208 | element(name: string, value?: Object): XMLDocType;
|
1209 | ele(name: string, value?: Object): XMLDocType;
|
1210 |
|
1211 | /**
|
1212 | * Creates an attribute declaration.
|
1213 | *
|
1214 | * _Alias:_ `att`
|
1215 | *
|
1216 | * @param elementName - the name of the element containing this attribute
|
1217 | * @param attributeName - attribute name
|
1218 | * @param attributeType - type of the attribute
|
1219 | * @param defaultValueType - default value type (either `#REQUIRED`,
|
1220 | * `#IMPLIED`, `#FIXED` or `#DEFAULT`)
|
1221 | * @param defaultValue - default value of the attribute (only used
|
1222 | * for `#FIXED` or `#DEFAULT`)
|
1223 | *
|
1224 | * @returns the DOCTYPE node
|
1225 | */
|
1226 | attList(elementName: string, attributeName: string, attributeType: string,
|
1227 | defaultValueType: string, defaultValue?: any): XMLDocType;
|
1228 | att(elementName: string, attributeName: string, attributeType: string,
|
1229 | defaultValueType: string, defaultValue?: any): XMLDocType;
|
1230 |
|
1231 | /**
|
1232 | * Creates a general entity declaration.
|
1233 | *
|
1234 | * _Alias:_ `ent`
|
1235 | *
|
1236 | * @param name - the name of the entity
|
1237 | * @param value - entity parameters
|
1238 | *
|
1239 | * @returns the DOCTYPE node
|
1240 | */
|
1241 | entity(name: string, value: string |
|
1242 | { pubID?: string, sysID?: string, nData?: string }): XMLDocType;
|
1243 | ent(name: string, value: string |
|
1244 | { pubID?: string, sysID?: string, nData?: string }): XMLDocType;
|
1245 |
|
1246 | /**
|
1247 | * Creates a parameter entity declaration.
|
1248 | *
|
1249 | * _Alias:_ `pent`
|
1250 | *
|
1251 | * @param name - the name of the entity
|
1252 | * @param value - entity parameters
|
1253 | *
|
1254 | * @returns the DOCTYPE node
|
1255 | */
|
1256 | pEntity(name: string, value: string |
|
1257 | { pubID?: string, sysID?: string }): XMLDocType;
|
1258 | pent(name: string, value: string |
|
1259 | { pubID?: string, sysID?: string }): XMLDocType;
|
1260 |
|
1261 | /**
|
1262 | * Creates a notation declaration.
|
1263 | *
|
1264 | * _Alias:_ `not`
|
1265 | *
|
1266 | * @param name - the name of the entity
|
1267 | * @param value - entity parameters
|
1268 | *
|
1269 | * @returns the DOCTYPE node
|
1270 | */
|
1271 | notation(name: string,
|
1272 | value: { pubID?: string, sysID?: string }): XMLDocType;
|
1273 | not(name: string,
|
1274 | value: { pubID?: string, sysID?: string }): XMLDocType;
|
1275 |
|
1276 | /**
|
1277 | * Creates a new CDATA node and appends it to the list of child nodes.
|
1278 | *
|
1279 | * _Alias:_ `dat`
|
1280 | *
|
1281 | * @param value - node value
|
1282 | *
|
1283 | * @returns the DOCTYPE node
|
1284 | */
|
1285 | cdata(value: string): XMLDocType;
|
1286 | dat(value: string): XMLDocType;
|
1287 |
|
1288 | /**
|
1289 | * Creates a new comment child and appends it to the list of child
|
1290 | * nodes.
|
1291 | *
|
1292 | * _Alias:_ `com`
|
1293 | *
|
1294 | * @param value - node value
|
1295 | *
|
1296 | * @returns the DOCTYPE node
|
1297 | */
|
1298 | comment(value: string): XMLDocType;
|
1299 | com(value: string): XMLDocType;
|
1300 |
|
1301 | /**
|
1302 | * Creates a new processing instruction node and appends it to the list
|
1303 | * of child nodes.
|
1304 | *
|
1305 | * _Alias:_ `ins`
|
1306 | *
|
1307 | * @param target - node target
|
1308 | * @param value - node value
|
1309 | *
|
1310 | * @returns the DOCTYPE node
|
1311 | */
|
1312 | instruction(target: string, value: any): XMLDocType;
|
1313 | instruction(array: Array<any>): XMLDocType;
|
1314 | instruction(obj: Object): XMLDocType;
|
1315 | ins(target: string, value: any): XMLDocType;
|
1316 | ins(array: Array<any>): XMLDocType;
|
1317 | ins(obj: Object): XMLDocType;
|
1318 |
|
1319 | /**
|
1320 | * Returns the root element node.
|
1321 | *
|
1322 | * _Alias:_ `up`
|
1323 | */
|
1324 | root(): XMLElement;
|
1325 | up(): XMLElement;
|
1326 |
|
1327 | /**
|
1328 | * Converts the node to string.
|
1329 | *
|
1330 | * @param options - conversion options
|
1331 | */
|
1332 | toString(options?: XMLToStringOptions): string;
|
1333 |
|
1334 | /**
|
1335 | * Creates a clone of this node.
|
1336 | */
|
1337 | clone(): XMLDocType;
|
1338 |
|
1339 | /**
|
1340 | * Returns the document node.
|
1341 | *
|
1342 | * _Alias:_ `doc`
|
1343 | */
|
1344 | document(): XMLDocument;
|
1345 | doc(): XMLDocument;
|
1346 |
|
1347 | /**
|
1348 | * Converts the XML document to string.
|
1349 | *
|
1350 | * @param options - conversion options
|
1351 | */
|
1352 | end(options?: XMLWriter | XMLToStringOptions): string;
|
1353 | }
|
1354 |
|
1355 | /**
|
1356 | * Represents an attribute list in the DTD.
|
1357 | */
|
1358 | class XMLDTDAttList {
|
1359 | /**
|
1360 | * The name of the element containing this attribute
|
1361 | */
|
1362 | elementName: string;
|
1363 | /**
|
1364 | * Attribute name
|
1365 | */
|
1366 | attributeName: string;
|
1367 | /**
|
1368 | * Type of the attribute
|
1369 | */
|
1370 | attributeType: string;
|
1371 | /**
|
1372 | * Default value type (either `#REQUIRED`, `#IMPLIED`, `#FIXED`
|
1373 | * or `#DEFAULT`)
|
1374 | */
|
1375 | defaultValueType: string;
|
1376 | /**
|
1377 | * Default value of the attribute (only used for `#FIXED` or
|
1378 | * `#DEFAULT`)
|
1379 | */
|
1380 | defaultValue: string;
|
1381 |
|
1382 | /**
|
1383 | * Converts the node to string.
|
1384 | *
|
1385 | * @param options - conversion options
|
1386 | */
|
1387 | toString(options?: XMLToStringOptions): string;
|
1388 | }
|
1389 |
|
1390 | /**
|
1391 | * Represents an element in the DTD.
|
1392 | */
|
1393 | class XMLDTDElement {
|
1394 | /**
|
1395 | * The name of the element
|
1396 | */
|
1397 | name: string;
|
1398 | /**
|
1399 | * Element content
|
1400 | */
|
1401 | value: string;
|
1402 |
|
1403 | /**
|
1404 | * Converts the node to string.
|
1405 | *
|
1406 | * @param options - conversion options
|
1407 | */
|
1408 | toString(options?: XMLToStringOptions): string;
|
1409 | }
|
1410 |
|
1411 | /**
|
1412 | * Represents an entity in the DTD.
|
1413 | */
|
1414 | class XMLDTDEntity {
|
1415 | /**
|
1416 | * Determines whether this is a parameter entity (`true`) or a
|
1417 | * general entity (`false`).
|
1418 | */
|
1419 | pe: boolean;
|
1420 | /**
|
1421 | * The name of the entity
|
1422 | */
|
1423 | name: string;
|
1424 | /**
|
1425 | * Public identifier
|
1426 | */
|
1427 | pubID: string;
|
1428 | /**
|
1429 | * System identifier
|
1430 | */
|
1431 | sysID: string;
|
1432 | /**
|
1433 | * Notation declaration
|
1434 | */
|
1435 | nData: string;
|
1436 |
|
1437 | /**
|
1438 | * Converts the node to string.
|
1439 | *
|
1440 | * @param options - conversion options
|
1441 | */
|
1442 | toString(options?: XMLToStringOptions): string;
|
1443 | }
|
1444 |
|
1445 | /**
|
1446 | * Represents a notation in the DTD.
|
1447 | */
|
1448 | class XMLDTDNotation {
|
1449 | /**
|
1450 | * The name of the notation
|
1451 | */
|
1452 | name: string;
|
1453 | /**
|
1454 | * Public identifier
|
1455 | */
|
1456 | pubID: string;
|
1457 | /**
|
1458 | * System identifier
|
1459 | */
|
1460 | sysID: string;
|
1461 |
|
1462 | /**
|
1463 | * Converts the node to string.
|
1464 | *
|
1465 | * @param options - conversion options
|
1466 | */
|
1467 | toString(options?: XMLToStringOptions): string;
|
1468 | }
|
1469 |
|
1470 | /**
|
1471 | * Represents an element node.
|
1472 | */
|
1473 | class XMLElement extends XMLNode {
|
1474 | /**
|
1475 | * Element node name
|
1476 | */
|
1477 | name: string;
|
1478 | /**
|
1479 | * Element attributes
|
1480 | */
|
1481 | attribs: { string: XMLAttribute };
|
1482 |
|
1483 | /**
|
1484 | * Creates a clone of this node
|
1485 | */
|
1486 | clone(): XMLElement;
|
1487 |
|
1488 | /**
|
1489 | * Adds or modifies an attribute.
|
1490 | *
|
1491 | * _Aliases:_ `att`, `a`
|
1492 | *
|
1493 | * @param name - attribute name
|
1494 | * @param value - attribute value
|
1495 | *
|
1496 | * @returns the parent element node
|
1497 | */
|
1498 | attribute(name: any, value?: any): XMLElement;
|
1499 | att(name: any, value?: any): XMLElement;
|
1500 | a(name: any, value?: any): XMLElement;
|
1501 |
|
1502 | /**
|
1503 | * Removes an attribute.
|
1504 | *
|
1505 | * @param name - attribute name
|
1506 | *
|
1507 | * @returns the parent element node
|
1508 | */
|
1509 | removeAttribute(name: string | string[]): XMLElement;
|
1510 |
|
1511 | /**
|
1512 | * Converts the node to string.
|
1513 | *
|
1514 | * @param options - conversion options
|
1515 | */
|
1516 | toString(options?: XMLToStringOptions): string;
|
1517 | }
|
1518 |
|
1519 | /**
|
1520 | * Represents an XML document builder used in callback mode with the
|
1521 | * `begin` function.
|
1522 | */
|
1523 | class XMLDocumentCB {
|
1524 |
|
1525 | /**
|
1526 | * Creates a new child node and appends it to the list of child nodes.
|
1527 | *
|
1528 | * _Aliases:_ `nod` and `n`
|
1529 | *
|
1530 | * @param name - element node name
|
1531 | * @param attributes - node attributes
|
1532 | * @param text - node text
|
1533 | *
|
1534 | * @returns the document builder object
|
1535 | */
|
1536 | node(name: string, attributes?: Object, text?: any): XMLDocumentCB;
|
1537 | nod(name: string, attributes?: Object, text?: any): XMLDocumentCB;
|
1538 | n(name: string, attributes?: Object, text?: any): XMLDocumentCB;
|
1539 |
|
1540 | /**
|
1541 | * Creates a child element node.
|
1542 | *
|
1543 | * _Aliases:_ `ele` and `e`
|
1544 | *
|
1545 | * @param name - element node name or a JS object defining the nodes
|
1546 | * to insert
|
1547 | * @param attributes - node attributes
|
1548 | * @param text - node text
|
1549 | *
|
1550 | * @returns the document builder object
|
1551 | */
|
1552 | element(name: any, attributes?: Object, text?: any): XMLDocumentCB;
|
1553 | ele(name: any, attributes?: Object, text?: any): XMLDocumentCB;
|
1554 | e(name: any, attributes?: Object, text?: any): XMLDocumentCB;
|
1555 |
|
1556 | /**
|
1557 | * Adds or modifies an attribute.
|
1558 | *
|
1559 | * _Aliases:_ `att` and `a`
|
1560 | *
|
1561 | * @param name - attribute name
|
1562 | * @param value - attribute value
|
1563 | *
|
1564 | * @returns the document builder object
|
1565 | */
|
1566 | attribute(name: any, value?: any): XMLDocumentCB;
|
1567 | att(name: any, value?: any): XMLDocumentCB;
|
1568 | a(name: any, value?: any): XMLDocumentCB;
|
1569 |
|
1570 | /**
|
1571 | * Creates a new text node and appends it to the list of child nodes.
|
1572 | *
|
1573 | * _Aliases:_ `txt` and `t`
|
1574 | *
|
1575 | * @param value - node value
|
1576 | *
|
1577 | * @returns the document builder object
|
1578 | */
|
1579 | text(value: string): XMLDocumentCB;
|
1580 | txt(value: string): XMLDocumentCB;
|
1581 | t(value: string): XMLDocumentCB;
|
1582 |
|
1583 | /**
|
1584 | * Creates a new CDATA node and appends it to the list of child nodes.
|
1585 | *
|
1586 | * _Aliases:_ `dat` and `d`
|
1587 | *
|
1588 | * @param value - node value
|
1589 | *
|
1590 | * @returns the document builder object
|
1591 | */
|
1592 | cdata(value: string): XMLDocumentCB;
|
1593 | dat(value: string): XMLDocumentCB;
|
1594 | d(value: string): XMLDocumentCB;
|
1595 |
|
1596 | /**
|
1597 | * Creates a new comment node and appends it to the list of child nodes.
|
1598 | *
|
1599 | * _Aliases:_ `com` and `c`
|
1600 | *
|
1601 | * @param value - node value
|
1602 | *
|
1603 | * @returns the document builder object
|
1604 | */
|
1605 | comment(value: string): XMLDocumentCB;
|
1606 | com(value: string): XMLDocumentCB;
|
1607 | c(value: string): XMLDocumentCB;
|
1608 |
|
1609 | /**
|
1610 | * Creates a new raw text node and appends it to the list of child
|
1611 | * nodes.
|
1612 | *
|
1613 | * _Alias:_ `r`
|
1614 | *
|
1615 | * @param value - node value
|
1616 | *
|
1617 | * @returns the document builder object
|
1618 | */
|
1619 | raw(value: string): XMLDocumentCB;
|
1620 | r(value: string): XMLDocumentCB;
|
1621 |
|
1622 | /**
|
1623 | * Creates a new processing instruction node and appends it to the list
|
1624 | * of child nodes.
|
1625 | *
|
1626 | * _Aliases:_ `ins` and `i`
|
1627 | *
|
1628 | * @param target - node target
|
1629 | * @param value - node value
|
1630 | *
|
1631 | * @returns the document builder object
|
1632 | */
|
1633 | instruction(target: string, value: any): XMLDocumentCB;
|
1634 | instruction(array: Array<any>): XMLDocumentCB;
|
1635 | instruction(obj: Object): XMLDocumentCB;
|
1636 | ins(target: string, value: any): XMLDocumentCB;
|
1637 | ins(array: Array<any>): XMLDocumentCB;
|
1638 | ins(obj: Object): XMLDocumentCB;
|
1639 | i(target: string, value: any): XMLDocumentCB;
|
1640 | i(array: Array<any>): XMLDocumentCB;
|
1641 | i(obj: Object): XMLDocumentCB;
|
1642 |
|
1643 | /**
|
1644 | * Creates the XML declaration.
|
1645 | *
|
1646 | * _Alias:_ `dec`
|
1647 | *
|
1648 | * @param version - version number string, e.g. `1.0`
|
1649 | * @param encoding - encoding declaration, e.g. `UTF-8`
|
1650 | * @param standalone - standalone document declaration: `true` or `false`
|
1651 | *
|
1652 | * @returns the document builder object
|
1653 | */
|
1654 | declaration(version?: string, encoding?: string,
|
1655 | standalone?: boolean): XMLDocumentCB;
|
1656 | dec(version?: string, encoding?: string,
|
1657 | standalone?: boolean): XMLDocumentCB;
|
1658 |
|
1659 | /**
|
1660 | * Creates the document type definition.
|
1661 | *
|
1662 | * _Alias:_ `dtd`
|
1663 | *
|
1664 | * @param root - the name of the root node
|
1665 | * @param pubID - public identifier of the DTD
|
1666 | * @param sysID - system identifier of the DTD
|
1667 | *
|
1668 | * @returns the document builder object
|
1669 | */
|
1670 | doctype(root: string, pubID?: string, sysID?: string): XMLDocumentCB;
|
1671 | dtd(root: string, pubID?: string, sysID?: string): XMLDocumentCB;
|
1672 |
|
1673 | /**
|
1674 | * Creates an element type declaration.
|
1675 | *
|
1676 | * _Aliases:_ `element` and `ele`
|
1677 | *
|
1678 | * @param name - element name
|
1679 | * @param value - element content (defaults to `#PCDATA`)
|
1680 | *
|
1681 | * @returns the document builder object
|
1682 | */
|
1683 | dtdElement(name: string, value?: Object): XMLDocumentCB;
|
1684 | element(name: string, value?: Object): XMLDocumentCB;
|
1685 | ele(name: string, value?: Object): XMLDocumentCB;
|
1686 |
|
1687 | /**
|
1688 | * Creates an attribute declaration.
|
1689 | *
|
1690 | * _Alias:_ `att`
|
1691 | *
|
1692 | * @param elementName - the name of the element containing this attribute
|
1693 | * @param attributeName - attribute name
|
1694 | * @param attributeType - type of the attribute (defaults to `CDATA`)
|
1695 | * @param defaultValueType - default value type (either `#REQUIRED`,
|
1696 | * `#IMPLIED`, `#FIXED` or `#DEFAULT`) (defaults to `#IMPLIED`)
|
1697 | * @param defaultValue - default value of the attribute (only used
|
1698 | * for `#FIXED` or `#DEFAULT`)
|
1699 | *
|
1700 | * @returns the document builder object
|
1701 | */
|
1702 | attList(elementName: string, attributeName: string,
|
1703 | attributeType: string, defaultValueType?:
|
1704 | string, defaultValue?: any): XMLDocumentCB;
|
1705 | att(elementName: string, attributeName: string, attributeType: string,
|
1706 | defaultValueType?: string, defaultValue?: any): XMLDocumentCB;
|
1707 | a(elementName: string, attributeName: string, attributeType: string,
|
1708 | defaultValueType?: string, defaultValue?: any): XMLDocumentCB;
|
1709 |
|
1710 | /**
|
1711 | * Creates a general entity declaration.
|
1712 | *
|
1713 | * _Alias:_ `ent`
|
1714 | *
|
1715 | * @param name - the name of the entity
|
1716 | * @param value - entity parameters
|
1717 | *
|
1718 | * @returns the document builder object
|
1719 | */
|
1720 | entity(name: string, value: string |
|
1721 | { pubID?: string, sysID?: string, nData?: string }): XMLDocumentCB;
|
1722 | ent(name: string, value: string |
|
1723 | { pubID?: string, sysID?: string, nData?: string }): XMLDocumentCB;
|
1724 |
|
1725 | /**
|
1726 | * Creates a parameter entity declaration.
|
1727 | *
|
1728 | * _Alias:_ `pent`
|
1729 | *
|
1730 | * @param name - the name of the entity
|
1731 | * @param value - entity parameters
|
1732 | *
|
1733 | * @returns the document builder object
|
1734 | */
|
1735 | pEntity(name: string, value: string |
|
1736 | { pubID?: string, sysID?: string }): XMLDocumentCB;
|
1737 | pent(name: string, value: string |
|
1738 | { pubID?: string, sysID?: string }): XMLDocumentCB;
|
1739 |
|
1740 | /**
|
1741 | * Creates a notation declaration.
|
1742 | *
|
1743 | * _Alias:_ `not`
|
1744 | *
|
1745 | * @param name - the name of the entity
|
1746 | * @param value - entity parameters
|
1747 | *
|
1748 | * @returns the document builder object
|
1749 | */
|
1750 | notation(name: string,
|
1751 | value: { pubID?: string, sysID?: string }): XMLDocumentCB;
|
1752 | not(name: string,
|
1753 | value: { pubID?: string, sysID?: string }): XMLDocumentCB;
|
1754 |
|
1755 | /**
|
1756 | * Ends the document and calls the `onEnd` callback function.
|
1757 | */
|
1758 | end(): void;
|
1759 |
|
1760 | /**
|
1761 | * Moves up to the parent node.
|
1762 | *
|
1763 | * _Alias:_ `u`
|
1764 | *
|
1765 | * @returns the document builder object
|
1766 | */
|
1767 | up(): XMLDocumentCB;
|
1768 | u(): XMLDocumentCB;
|
1769 | }
|
1770 |
|
1771 | }
|