-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.d.ts
266 lines (227 loc) · 6.66 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import { EventEmitter } from 'events';
export const version: string;
export const libxml_version: string;
export const libxml_parser_version: string;
interface StringMap {
[key: string]: string;
}
interface ParserOptions {
recover?: boolean;
noent?: boolean;
dtdload?: boolean;
doctype?: boolean;
dtdattr?: any;
dtdvalid?: boolean;
noerror?: boolean;
errors?: boolean;
nowarning?: boolean;
warnings?: boolean;
pedantic?: boolean;
noblanks?: boolean;
blanks?: boolean;
sax1?: boolean;
xinclude?: boolean;
nonet?: boolean;
net?: boolean;
nodict?: boolean;
dict?: boolean;
nsclean?: boolean;
implied?: boolean;
nocdata?: boolean;
cdata?: boolean;
noxincnode?: boolean;
compact?: boolean;
old?: boolean;
nobasefix?: boolean;
basefix?: boolean;
huge?: boolean;
oldsax?: boolean;
ignore_enc?: boolean;
big_lines?: boolean;
baseUrl?: string;
}
export function parseXml(source: string, options?: ParserOptions): Document;
export function parseXmlString(
source: string,
options?: ParserOptions
): Document;
export function parseHtml(source: string, options?: ParserOptions): Document;
export function parseHtmlString(
source: string,
options?: ParserOptions
): Document;
export function parseHtmlFragment(
source: string,
options?: ParserOptions
): Document;
export function memoryUsage(): number;
export function nodeCount(): number;
export class Document {
/**
* Create a new XML Document
* @param version XML document version, defaults to 1.0
* @param encoding Encoding, defaults to utf8
*/
constructor(version?: string, encoding?: string);
errors: SyntaxError[];
validationErrors: ValidationError[];
child(idx: number): Node | null;
childNodes(): Node[];
encoding(): string;
encoding(enc: string): this;
find<T extends Node = Node>(xpath: string, ns_uri?: string): T[];
find<T extends Node = Node>(xpath: string, namespaces: StringMap): T[];
get<T extends Node = Node>(xpath: string, ns_uri?: string): T | null;
get<T extends Node = Node>(xpath: string, namespaces: StringMap): T | null;
node(name: string, content?: string): Element;
root(): Element | null;
root(newRoot: Node): Node;
toString(formatted?: boolean): string;
type(): 'document';
validate(xsdDoc: Document): boolean;
schematronValidate(schemaDoc: Document): boolean;
version(): string;
setDtd(name: string, ext: string, sys: string): void;
getDtd(): {
name: string;
externalId: string;
systemId: string;
};
}
export class Node {
doc(): Document;
parent(): Element | Document;
/**
* The namespace or null in case of comment nodes
*/
namespace(): Namespace | null;
/**
* An array of namespaces that the object belongs to.
*
* @param local If it is true, only the namespace declarations local to this
* node are returned, rather than all of the namespaces in scope
* at this node (including the ones from the parent elements).
*/
namespaces(local?: boolean): Namespace[];
prevSibling(): Node | null;
nextSibling(): Node | null;
line(): number;
type(): 'comment' | 'element' | 'text' | 'attribute' | 'pi';
remove(): this;
clone(): this;
/**
* Serializes the node to a string. The string will contain all contents of the node formatted as XML and can be used to print the node.
*/
toString(
format?:
| boolean
| {
declaration: boolean;
selfCloseEmpty: boolean;
whitespace: boolean;
type: 'xml' | 'html' | 'xhtml';
}
): string;
}
export class Element extends Node {
constructor(doc: Document, name: string, content?: string);
node(name: string, content?: string): Element;
name(): string;
name(newName: string): this;
text(): string;
text(newText: string): this;
attr(name: string): Attribute | null; //getter
attr(name: string, value: string): this; //setter
attr(attrObject: StringMap): this; //setter using stringMap
attrs(): Attribute[];
cdata(data: string): this;
doc(): Document;
child(idx: number): Node | null;
childNodes(): Node[];
/**
* @return The original element, not the child.
*/
addChild(child: Node): this;
prevElement(): Element | null;
nextElement(): Element | null;
addNextSibling<T extends Node>(siblingNode: T): T;
addPrevSibling<T extends Node>(siblingNode: T): T;
find<T extends Node = Node>(xpath: string, ns_uri?: string): T[];
find<T extends Node = Node>(xpath: string, namespaces: StringMap): T[];
get<T extends Node = Node>(xpath: string, ns_uri?: string): T | null;
get<T extends Node = Node>(xpath: string, namespaces: StringMap): T | null;
defineNamespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): Namespace;
namespace(): Namespace | null;
namespace(newNamespace: Namespace): this;
namespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): this;
replace(replacement: string): string;
replace<T extends Node>(replacement: T): T;
path(): string;
}
declare class Attribute extends Node {
name(): string;
node(): Element;
value(): string;
value(newValue: string): Attribute;
namespace(): Namespace | null;
}
export class Text extends Node {
constructor(doc: Document, content: string);
addNextSibling<T extends Node>(siblingNode: T): T;
addPrevSibling<T extends Node>(siblingNode: T): T;
nextElement(): Element | null;
prevElement(): Element | null;
replace(replacement: string): string;
replace<T extends Node>(replacement: T): T;
text(): string;
text(newContent: string): this;
}
export class Comment extends Node {
constructor(doc: Document, content?: string);
text(): string;
text(newContent: string): this;
}
export class ProcessingInstruction extends Node {
constructor(doc: Document, name: string, content?: string);
name(): string;
name(newName: string): this;
text(): string;
text(newContent: string): this;
}
export class Namespace {
href(): string;
prefix(): string;
}
export class SaxParser extends EventEmitter {
constructor();
parseString(source: string): boolean;
}
export class SaxPushParser extends EventEmitter {
constructor();
push(source: string): boolean;
}
export interface SyntaxError extends Error {
domain: number | null;
code: number | null;
level: number | null;
file: string | null;
line: number | null;
/**
* 1-based column number, 0 if not applicable/available.
*/
column: number;
str1: number | null;
str2: number | null;
str3: number | null;
int1: number | null;
}
export interface ValidationError extends Error {
domain: number | null;
code: number | null;
level: number | null;
line: number | null;
/**
* 1-based column number, 0 if not applicable/available.
*/
column: number;
}