UNPKG

5.31 kBTypeScriptView Raw
1/**
2 * Copyright (C) 2016-2019 Michael Kourlas
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { IStringOptions } from "../options";
17import XmlComment, { IXmlCommentOptions } from "./XmlComment";
18import XmlDtdAttlist, { IXmlDtdAttlistOptions } from "./XmlDtdAttlist";
19import XmlDtdElement, { IXmlDtdElementOptions } from "./XmlDtdElement";
20import XmlDtdEntity, { IXmlDtdEntityOptions } from "./XmlDtdEntity";
21import XmlDtdNotation, { IXmlDtdNotationOptions } from "./XmlDtdNotation";
22import { default as XmlDtdParamEntityRef, IXmlDtdParamEntityRefOptions } from "./XmlDtdParamEntityRef";
23import XmlProcInst, { IXmlProcInstOptions } from "./XmlProcInst";
24/**
25 * The options used to create a new document type definition.
26 */
27export interface IXmlDtdOptions {
28 /**
29 * The name of the DTD.
30 */
31 name: string;
32 /**
33 * The system identifier of the DTD, excluding quotation marks. By default,
34 * no system identifier is included.
35 */
36 sysId?: string;
37 /**
38 * The public identifier of the DTD, excluding quotation marks. If a public
39 * identifier is provided, a system identifier must be provided as well.
40 * By default, no public identifier is included.
41 */
42 pubId?: string;
43}
44/**
45 * Represents an XML document type definition (DTD).
46 *
47 * A document type definition is structured as follows, where `{name}` is
48 * the name of the DTD, `{sysId}` is the system identifier of the DTD,
49 * `{pubId}` is the public identifier of the DTD, and `{intSubset}` is the
50 * internal subset of the DTD:
51 *
52 * ```xml
53 * <!DOCTYPE {name} SYSTEM "{sysId}" PUBLIC "{pubId}" [
54 * {intSubset}
55 * ]>
56 * ```
57 *
58 * DTDs can have an unlimited number of comments, attribute-list declarations,
59 * element declarations, entity declarations, notation declarations, parameter
60 * entity references, and processing instructions.
61 */
62export default class XmlDtd<Parent> {
63 private readonly _children;
64 private readonly _parent;
65 private _name;
66 private readonly _validation;
67 private _pubId;
68 private _sysId;
69 constructor(parent: Parent, validation: boolean, options: IXmlDtdOptions);
70 /**
71 * Gets the name of the DTD.
72 */
73 get name(): string;
74 /**
75 * Sets the name of the DTD.
76 */
77 set name(name: string);
78 /**
79 * Gets the public identifier of the DTD.
80 */
81 get pubId(): string | undefined;
82 /**
83 * Sets the public identifier of the DTD.
84 */
85 set pubId(pubId: string | undefined);
86 /**
87 * Gets the system identifier of the DTD.
88 */
89 get sysId(): string | undefined;
90 /**
91 * Sets the system identifier of the DTD.
92 */
93 set sysId(sysId: string | undefined);
94 /**
95 * Adds an attribute-list declaration to this document type declaration
96 * and returns the new attribute-list declaration.
97 */
98 attlist(options: IXmlDtdAttlistOptions): XmlDtdAttlist<this>;
99 /**
100 * Adds a comment to this document type declaration and returns the
101 * new comment.
102 */
103 comment(options: IXmlCommentOptions): XmlComment<this>;
104 /**
105 * Adds an element declaration to this document type declaration
106 * and returns the new element declaration.
107 */
108 element(options: IXmlDtdElementOptions): XmlDtdElement<this>;
109 /**
110 * Adds an entity declaration to this document type declaration
111 * and returns the new entity declaration.
112 */
113 entity(options: IXmlDtdEntityOptions): XmlDtdEntity<this>;
114 /**
115 * Adds a notation declaration to this document type declaration
116 * and returns the new notation declaration.
117 */
118 notation(options: IXmlDtdNotationOptions): XmlDtdNotation<this>;
119 /**
120 * Adds a parameter entity reference to this document type declaration
121 * and returns the new parameter entity reference.
122 */
123 paramEntityRef(options: IXmlDtdParamEntityRefOptions): XmlDtdParamEntityRef<this>;
124 /**
125 * Adds a processing instruction to this document type declaration
126 * and returns the new processing instruction.
127 */
128 procInst(options: IXmlProcInstOptions): XmlProcInst<this>;
129 /**
130 * Returns an XML string representation of this document type declaration.
131 */
132 toString(options?: IStringOptions): string;
133 /**
134 * Returns the parent of this attribute.
135 */
136 up(): Parent;
137 /**
138 * Appends the XML string representation of a public or system identifier
139 * to an existing string.
140 */
141 private appendId;
142}
143/**
144 * Returns true if the specified public identifier only contains characters
145 * permitted by the XML specification.
146 */
147export declare function validatePubId(str: string): boolean;