1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { IStringOptions } from "../options";
|
17 | import { default as XmlAttribute, IXmlAttributeOptions as IXmlAttributeOptions } from "./XmlAttribute";
|
18 | import XmlCdata, { IXmlCdataOptions } from "./XmlCdata";
|
19 | import XmlCharData, { IXmlCharDataOptions } from "./XmlCharData";
|
20 | import XmlCharRef, { IXmlCharRefOptions } from "./XmlCharRef";
|
21 | import XmlComment, { IXmlCommentOptions } from "./XmlComment";
|
22 | import XmlEntityRef, { IXmlEntityRefOptions } from "./XmlEntityRef";
|
23 | import XmlProcInst, { IXmlProcInstOptions } from "./XmlProcInst";
|
24 |
|
25 |
|
26 |
|
27 | export interface IXmlElementOptions {
|
28 | |
29 |
|
30 |
|
31 | name: string;
|
32 | |
33 |
|
34 |
|
35 |
|
36 | replaceInvalidCharsInName?: boolean;
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | useSelfClosingTagIfEmpty?: boolean;
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export default class XmlElement<Parent> {
|
78 | private readonly _validation;
|
79 | private readonly _children;
|
80 | private readonly _attributeNames;
|
81 | private readonly _parent;
|
82 | private readonly _replaceInvalidCharsInName;
|
83 | private readonly _useSelfClosingTagIfEmpty;
|
84 | private _name;
|
85 | constructor(parent: Parent, validation: boolean, options: IXmlElementOptions);
|
86 | /**
|
87 | * Gets the name of this element.
|
88 | */
|
89 | get name(): string;
|
90 | /**
|
91 | * Sets the name of this element.
|
92 | */
|
93 | set name(name: string);
|
94 | /**
|
95 | * Adds an attribute to this element and returns the new attribute.
|
96 | */
|
97 | attribute(options: IXmlAttributeOptions): XmlAttribute<this>;
|
98 | /**
|
99 | * Adds a CDATA section to this element and returns the new CDATA section.
|
100 | */
|
101 | cdata(options: IXmlCdataOptions): XmlCdata<this>;
|
102 | /**
|
103 | * Adds character data to this element and returns the new character data.
|
104 | */
|
105 | charData(options: IXmlCharDataOptions): XmlCharData<this>;
|
106 | /**
|
107 | * Adds a character reference to this element and returns the new
|
108 | * character reference.
|
109 | */
|
110 | charRef(options: IXmlCharRefOptions): XmlCharRef<this>;
|
111 | /**
|
112 | * Adds a comment to this element and returns the new comment.
|
113 | */
|
114 | comment(options: IXmlCommentOptions): XmlComment<this>;
|
115 | /**
|
116 | * Adds an element to this element and returns the new element.
|
117 | */
|
118 | element(options: IXmlElementOptions): XmlElement<this>;
|
119 | /**
|
120 | * Adds an entity reference to this element and returns the new entity
|
121 | * reference.
|
122 | */
|
123 | entityRef(options: IXmlEntityRefOptions): XmlEntityRef<this>;
|
124 | /**
|
125 | * Adds a processing instruction to this element and returns the new
|
126 | * processing instruction.
|
127 | */
|
128 | procInst(options: IXmlProcInstOptions): XmlProcInst<this>;
|
129 | /**
|
130 | * Returns an XML string representation of this element using the specified
|
131 | * options.
|
132 | */
|
133 | toString(options?: IStringOptions): string;
|
134 | /**
|
135 | * Returns the parent of this element.
|
136 | */
|
137 | up(): Parent;
|
138 | /**
|
139 | * Returns an XML string representation of this element using the specified
|
140 | * options and initial indent.
|
141 | */
|
142 | private toStringWithIndent;
|
143 | /**
|
144 | * Returns true if the specified nodes are all character references,
|
145 | * entity references, or character data.
|
146 | */
|
147 | private allSameLineNodes;
|
148 | /**
|
149 | * Returns true if the specified nodes are all character references,
|
150 | * entity references, or character data.
|
151 | */
|
152 | private onSameLine;
|
153 | }
|