新增调试信息
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
## 2.0.4 ##
|
||||
|
||||
* Update dependencies
|
||||
* Bug fixes
|
||||
|
||||
## 2.0.3 ##
|
||||
|
||||
* Bug fixes
|
||||
|
||||
## 2.0.2 ##
|
||||
|
||||
* Update dependencies
|
||||
* Use ESLint instead of TSLint
|
||||
* Use npm instead of gulp
|
||||
|
||||
## 2.0.1 ##
|
||||
|
||||
* Bug fixes
|
||||
|
||||
## 2.0.0 ##
|
||||
|
||||
* API rewrite and simplification
|
||||
* Add option to use self-closing tags if an element is empty
|
||||
* Stop indenting multi-line strings
|
||||
* Add option to automatically fix strings that are not valid XML in certain
|
||||
cases
|
||||
* More detailed error messages
|
||||
* Other bug fixes
|
||||
|
||||
## 1.0.2 ##
|
||||
|
||||
* Bug fixes
|
||||
|
||||
## 1.0.1 ##
|
||||
|
||||
* Documentation fixes
|
||||
|
||||
## 1.0.0 ##
|
||||
|
||||
* Add null and undefined in type declarations
|
||||
* Replace `XmlText` with `XmlCharData` and `XmlAttributeText` to reflect
|
||||
differences in what characters are acceptable in attribute values versus
|
||||
character data
|
||||
|
||||
## 0.1.1 ##
|
||||
|
||||
* Re-write in TypeScript
|
||||
* Remove expensive dependencies (especially babel-runtime)
|
||||
* Bug fixes and documentation fixes
|
||||
|
||||
## 0.1.0 ##
|
||||
|
||||
* Initial release
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
xmlcreate
|
||||
Copyright (C) 2016-2021 Michael Kourlas
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
# xmlcreate #
|
||||
|
||||
[](https://github.com/michaelkourlas/node-xmlcreate/actions/workflows/node.js.yml)
|
||||
[](https://badge.fury.io/js/xmlcreate)
|
||||
|
||||
## Overview ##
|
||||
|
||||
xmlcreate is a Node.js module that can be used to build XML using a simple API.
|
||||
|
||||
## Features ##
|
||||
|
||||
xmlcreate allows you to use a series of chained function calls to build an XML
|
||||
tree.
|
||||
|
||||
Once the tree is built, it can be serialized to text. The formatting of the
|
||||
text is customizable.
|
||||
|
||||
xmlcreate can perform some basic validation to check that the resulting XML
|
||||
is well-formed.
|
||||
|
||||
## Installation ##
|
||||
|
||||
The easiest way to install xmlcreate is using npm:
|
||||
|
||||
```
|
||||
npm install xmlcreate
|
||||
```
|
||||
|
||||
You can also build xmlcreate from source using npm:
|
||||
|
||||
```
|
||||
git clone https://github.com/michaelkourlas/node-xmlcreate.git
|
||||
npm install
|
||||
npm run-script build
|
||||
```
|
||||
|
||||
The `build` script will build the production variant of xmlcreate, run all
|
||||
tests, and build the documentation.
|
||||
|
||||
You can build the production variant without running tests using the script
|
||||
`prod`. You can also build the development version using the script `dev`.
|
||||
The only difference between the two is that the development version includes
|
||||
source maps.
|
||||
|
||||
## Usage ##
|
||||
|
||||
The documentation for the current version is available [here](http://www.kourlas.com/node-xmlcreate/docs/2.0.4/).
|
||||
|
||||
You can also build the documentation using npm:
|
||||
|
||||
```
|
||||
npm run-script docs
|
||||
```
|
||||
|
||||
## Examples ##
|
||||
|
||||
The following TypeScript example illustrates the basic usage of xmlcreate:
|
||||
|
||||
```typescript
|
||||
import {document} from "xmlcreate";
|
||||
|
||||
const tree = document();
|
||||
tree
|
||||
.decl({encoding: "UTF-8"})
|
||||
.up()
|
||||
.dtd({
|
||||
name: "html",
|
||||
pubId: "-//W3C//DTD XHTML 1.0 Strict//EN",
|
||||
sysId: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
|
||||
})
|
||||
.up()
|
||||
.element({name: "html"})
|
||||
.attribute({name: "xmlns"})
|
||||
.text({charData: "http://www.w3.org/1999/xhtml"})
|
||||
.up()
|
||||
.up()
|
||||
.attribute({name: "xml:lang"})
|
||||
.text({charData: "en"})
|
||||
.up()
|
||||
.up()
|
||||
.element({name: "head"})
|
||||
.element({name: "title"})
|
||||
.charData({charData: "My page title"})
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.element({name: "body"})
|
||||
.element({name: "h1"})
|
||||
.charData({charData: "Welcome!"})
|
||||
.up()
|
||||
.up()
|
||||
.element({name: "p"})
|
||||
.charData({charData: "This is some text on my website."})
|
||||
.up()
|
||||
.up()
|
||||
.element({name: "div"})
|
||||
.element({name: "img"})
|
||||
.attribute({name: "src"})
|
||||
.text({charData: "picture.png"})
|
||||
.up()
|
||||
.up()
|
||||
.attribute({name: "alt"})
|
||||
.text({charData: "picture"}).up().up().up().up().up();
|
||||
|
||||
console.log(tree.toString({doubleQuotes: true}));
|
||||
```
|
||||
|
||||
This example produces the following XML:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>My page title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome!</h1>
|
||||
<p>This is some text on my website.</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
A JavaScript version of this example can be found in the examples directory.
|
||||
|
||||
## Tests ##
|
||||
|
||||
xmlcreate includes a set of tests to verify core functionality. You can run
|
||||
the tests using npm:
|
||||
|
||||
```
|
||||
npm run-script test-prod
|
||||
```
|
||||
|
||||
The only difference between the `test-prod` and `test-dev` scripts is that the
|
||||
development version includes source maps.
|
||||
|
||||
## License ##
|
||||
|
||||
xmlcreate is licensed under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
||||
Please see the LICENSE file for more information.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (C) 2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Returns a context string for the specified node, for use in error messages.
|
||||
*/
|
||||
export declare function getContext(obj: unknown): string;
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getContext = void 0;
|
||||
var XmlAttribute_1 = __importDefault(require("./nodes/XmlAttribute"));
|
||||
var XmlDocument_1 = __importDefault(require("./nodes/XmlDocument"));
|
||||
var XmlDtd_1 = __importDefault(require("./nodes/XmlDtd"));
|
||||
var XmlElement_1 = __importDefault(require("./nodes/XmlElement"));
|
||||
/**
|
||||
* Returns a context string for the specified node, for use in error messages.
|
||||
*/
|
||||
function getContext(obj) {
|
||||
if (obj instanceof XmlAttribute_1.default) {
|
||||
return getContext(obj.up()) + (" > attribute \"" + obj.name + "\"");
|
||||
}
|
||||
else if (obj instanceof XmlDocument_1.default) {
|
||||
return "in XML document";
|
||||
}
|
||||
else if (obj instanceof XmlDtd_1.default) {
|
||||
return getContext(obj.up()) + " > DTD";
|
||||
}
|
||||
else if (obj instanceof XmlElement_1.default) {
|
||||
return getContext(obj.up()) + (" > element \"" + obj.name + "\"");
|
||||
}
|
||||
else {
|
||||
throw new Error("Unrecognized object of type "
|
||||
+ Object.prototype.toString.call(obj));
|
||||
}
|
||||
}
|
||||
exports.getContext = getContext;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2018 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Replaces ampersands (&) with the appropriate XML character reference.
|
||||
*/
|
||||
export declare function escapeAmpersands(str: string): string;
|
||||
/**
|
||||
* Replaces left angle brackets (<) with the appropriate XML character
|
||||
* reference.
|
||||
*/
|
||||
export declare function escapeLeftAngleBrackets(str: string): string;
|
||||
/**
|
||||
* Replaces right angle brackets (>) with the appropriate XML character
|
||||
* reference when part of the string "]]>".
|
||||
*/
|
||||
export declare function escapeRightAngleBracketsInCdataTerminator(str: string): string;
|
||||
/**
|
||||
* Replaces single quotes (") with the appropriate XML character reference.
|
||||
*/
|
||||
export declare function escapeSingleQuotes(str: string): string;
|
||||
/**
|
||||
* Replaces double quotes (") with the appropriate XML character reference.
|
||||
*/
|
||||
export declare function escapeDoubleQuotes(str: string): string;
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2018 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.escapeDoubleQuotes = exports.escapeSingleQuotes = exports.escapeRightAngleBracketsInCdataTerminator = exports.escapeLeftAngleBrackets = exports.escapeAmpersands = void 0;
|
||||
/**
|
||||
* Replaces ampersands (&) with the appropriate XML character reference.
|
||||
*/
|
||||
function escapeAmpersands(str) {
|
||||
return str.replace(/&/g, "&");
|
||||
}
|
||||
exports.escapeAmpersands = escapeAmpersands;
|
||||
/**
|
||||
* Replaces left angle brackets (<) with the appropriate XML character
|
||||
* reference.
|
||||
*/
|
||||
function escapeLeftAngleBrackets(str) {
|
||||
return str.replace(/</g, "<");
|
||||
}
|
||||
exports.escapeLeftAngleBrackets = escapeLeftAngleBrackets;
|
||||
/**
|
||||
* Replaces right angle brackets (>) with the appropriate XML character
|
||||
* reference when part of the string "]]>".
|
||||
*/
|
||||
function escapeRightAngleBracketsInCdataTerminator(str) {
|
||||
return str.replace(/]]>/g, "]]>");
|
||||
}
|
||||
exports.escapeRightAngleBracketsInCdataTerminator = escapeRightAngleBracketsInCdataTerminator;
|
||||
/**
|
||||
* Replaces single quotes (") with the appropriate XML character reference.
|
||||
*/
|
||||
function escapeSingleQuotes(str) {
|
||||
return str.replace(/'/g, "'");
|
||||
}
|
||||
exports.escapeSingleQuotes = escapeSingleQuotes;
|
||||
/**
|
||||
* Replaces double quotes (") with the appropriate XML character reference.
|
||||
*/
|
||||
function escapeDoubleQuotes(str) {
|
||||
return str.replace(/"/g, """);
|
||||
}
|
||||
exports.escapeDoubleQuotes = escapeDoubleQuotes;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import XmlDocument, { IXmlDocumentOptions } from "./nodes/XmlDocument";
|
||||
export { default as XmlAttribute, IXmlAttributeOptions } from "./nodes/XmlAttribute";
|
||||
export { default as XmlAttributeText, IXmlAttributeTextOptions } from "./nodes/XmlAttributeText";
|
||||
export { default as XmlCdata, IXmlCdataOptions } from "./nodes/XmlCdata";
|
||||
export { default as XmlCharData, IXmlCharDataOptions } from "./nodes/XmlCharData";
|
||||
export { default as XmlCharRef, IXmlCharRefOptions } from "./nodes/XmlCharRef";
|
||||
export { default as XmlComment, IXmlCommentOptions } from "./nodes/XmlComment";
|
||||
export { default as XmlDecl, IXmlDeclOptions } from "./nodes/XmlDecl";
|
||||
export { default as XmlDocument, IXmlDocumentOptions } from "./nodes/XmlDocument";
|
||||
export { default as XmlDtd, IXmlDtdOptions } from "./nodes/XmlDtd";
|
||||
export { default as XmlDtdAttlist, IXmlDtdAttlistOptions } from "./nodes/XmlDtdAttlist";
|
||||
export { default as XmlDtdElement, IXmlDtdElementOptions } from "./nodes/XmlDtdElement";
|
||||
export { default as XmlDtdEntity, IXmlDtdEntityOptions } from "./nodes/XmlDtdEntity";
|
||||
export { default as XmlDtdNotation, IXmlDtdNotationOptions } from "./nodes/XmlDtdNotation";
|
||||
export { default as XmlDtdParamEntityRef, IXmlDtdParamEntityRefOptions } from "./nodes/XmlDtdParamEntityRef";
|
||||
export { default as XmlElement, IXmlElementOptions } from "./nodes/XmlElement";
|
||||
export { default as XmlEntityRef, IXmlEntityRefOptions } from "./nodes/XmlEntityRef";
|
||||
export { default as XmlProcInst, IXmlProcInstOptions } from "./nodes/XmlProcInst";
|
||||
export { IStringOptions } from "./options";
|
||||
/**
|
||||
* Returns a new XML document with the specified options.
|
||||
*/
|
||||
export declare function document(options?: IXmlDocumentOptions): XmlDocument;
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.document = exports.XmlProcInst = exports.XmlEntityRef = exports.XmlElement = exports.XmlDtdParamEntityRef = exports.XmlDtdNotation = exports.XmlDtdEntity = exports.XmlDtdElement = exports.XmlDtdAttlist = exports.XmlDtd = exports.XmlDocument = exports.XmlDecl = exports.XmlComment = exports.XmlCharRef = exports.XmlCharData = exports.XmlCdata = exports.XmlAttributeText = exports.XmlAttribute = void 0;
|
||||
var XmlDocument_1 = __importDefault(require("./nodes/XmlDocument"));
|
||||
var XmlAttribute_1 = require("./nodes/XmlAttribute");
|
||||
Object.defineProperty(exports, "XmlAttribute", { enumerable: true, get: function () { return __importDefault(XmlAttribute_1).default; } });
|
||||
var XmlAttributeText_1 = require("./nodes/XmlAttributeText");
|
||||
Object.defineProperty(exports, "XmlAttributeText", { enumerable: true, get: function () { return __importDefault(XmlAttributeText_1).default; } });
|
||||
var XmlCdata_1 = require("./nodes/XmlCdata");
|
||||
Object.defineProperty(exports, "XmlCdata", { enumerable: true, get: function () { return __importDefault(XmlCdata_1).default; } });
|
||||
var XmlCharData_1 = require("./nodes/XmlCharData");
|
||||
Object.defineProperty(exports, "XmlCharData", { enumerable: true, get: function () { return __importDefault(XmlCharData_1).default; } });
|
||||
var XmlCharRef_1 = require("./nodes/XmlCharRef");
|
||||
Object.defineProperty(exports, "XmlCharRef", { enumerable: true, get: function () { return __importDefault(XmlCharRef_1).default; } });
|
||||
var XmlComment_1 = require("./nodes/XmlComment");
|
||||
Object.defineProperty(exports, "XmlComment", { enumerable: true, get: function () { return __importDefault(XmlComment_1).default; } });
|
||||
var XmlDecl_1 = require("./nodes/XmlDecl");
|
||||
Object.defineProperty(exports, "XmlDecl", { enumerable: true, get: function () { return __importDefault(XmlDecl_1).default; } });
|
||||
var XmlDocument_2 = require("./nodes/XmlDocument");
|
||||
Object.defineProperty(exports, "XmlDocument", { enumerable: true, get: function () { return __importDefault(XmlDocument_2).default; } });
|
||||
var XmlDtd_1 = require("./nodes/XmlDtd");
|
||||
Object.defineProperty(exports, "XmlDtd", { enumerable: true, get: function () { return __importDefault(XmlDtd_1).default; } });
|
||||
var XmlDtdAttlist_1 = require("./nodes/XmlDtdAttlist");
|
||||
Object.defineProperty(exports, "XmlDtdAttlist", { enumerable: true, get: function () { return __importDefault(XmlDtdAttlist_1).default; } });
|
||||
var XmlDtdElement_1 = require("./nodes/XmlDtdElement");
|
||||
Object.defineProperty(exports, "XmlDtdElement", { enumerable: true, get: function () { return __importDefault(XmlDtdElement_1).default; } });
|
||||
var XmlDtdEntity_1 = require("./nodes/XmlDtdEntity");
|
||||
Object.defineProperty(exports, "XmlDtdEntity", { enumerable: true, get: function () { return __importDefault(XmlDtdEntity_1).default; } });
|
||||
var XmlDtdNotation_1 = require("./nodes/XmlDtdNotation");
|
||||
Object.defineProperty(exports, "XmlDtdNotation", { enumerable: true, get: function () { return __importDefault(XmlDtdNotation_1).default; } });
|
||||
var XmlDtdParamEntityRef_1 = require("./nodes/XmlDtdParamEntityRef");
|
||||
Object.defineProperty(exports, "XmlDtdParamEntityRef", { enumerable: true, get: function () { return __importDefault(XmlDtdParamEntityRef_1).default; } });
|
||||
var XmlElement_1 = require("./nodes/XmlElement");
|
||||
Object.defineProperty(exports, "XmlElement", { enumerable: true, get: function () { return __importDefault(XmlElement_1).default; } });
|
||||
var XmlEntityRef_1 = require("./nodes/XmlEntityRef");
|
||||
Object.defineProperty(exports, "XmlEntityRef", { enumerable: true, get: function () { return __importDefault(XmlEntityRef_1).default; } });
|
||||
var XmlProcInst_1 = require("./nodes/XmlProcInst");
|
||||
Object.defineProperty(exports, "XmlProcInst", { enumerable: true, get: function () { return __importDefault(XmlProcInst_1).default; } });
|
||||
/**
|
||||
* Returns a new XML document with the specified options.
|
||||
*/
|
||||
function document(options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return new XmlDocument_1.default(options);
|
||||
}
|
||||
exports.document = document;
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IStringOptions } from "../options";
|
||||
import XmlAttributeText, { IXmlAttributeTextOptions } from "./XmlAttributeText";
|
||||
import XmlCharRef, { IXmlCharRefOptions } from "./XmlCharRef";
|
||||
import XmlEntityRef, { IXmlEntityRefOptions } from "./XmlEntityRef";
|
||||
/**
|
||||
* The options used to create a new attribute.
|
||||
*/
|
||||
export interface IXmlAttributeOptions {
|
||||
/**
|
||||
* The name of the attribute.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Whether to replace any invalid characters in the name of the attribute
|
||||
* with the Unicode replacement character. By default, this is disabled.
|
||||
*/
|
||||
replaceInvalidCharsInName?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents an attribute.
|
||||
*
|
||||
* An attribute is part of the start tag of an element and is
|
||||
* structured as follows, where `{name}` is the name of the attribute and
|
||||
* `{value}` is the value of the attribute:
|
||||
*
|
||||
* ```xml
|
||||
* <element {name}="{value}">
|
||||
* ```
|
||||
*
|
||||
* The `{name}` value is a property of this node, while the `{value}` property
|
||||
* consists of the children of this node.
|
||||
*
|
||||
* Attributes can have an unlimited number of attribute text, character
|
||||
* references, and entity references.
|
||||
*/
|
||||
export default class XmlAttribute<Parent> {
|
||||
private readonly _children;
|
||||
private readonly _replaceInvalidCharsInName;
|
||||
private readonly _parent;
|
||||
private readonly _validation;
|
||||
private _name;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlAttributeOptions);
|
||||
/**
|
||||
* Gets the name of this attribute.
|
||||
*/
|
||||
get name(): string;
|
||||
/**
|
||||
* Sets the name of this attribute.
|
||||
*/
|
||||
set name(name: string);
|
||||
/**
|
||||
* Adds a character reference to this attribute and returns the new
|
||||
* character reference.
|
||||
*/
|
||||
charRef(options: IXmlCharRefOptions): XmlCharRef<this>;
|
||||
/**
|
||||
* Adds an entity reference to this attribute and returns the new entity
|
||||
* reference.
|
||||
*/
|
||||
entityRef(options: IXmlEntityRefOptions): XmlEntityRef<this>;
|
||||
/**
|
||||
* Adds attribute text to this attribute and returns the new text.
|
||||
*/
|
||||
text(options: IXmlAttributeTextOptions): XmlAttributeText<this>;
|
||||
/**
|
||||
* Returns an XML string representation of this attribute.
|
||||
*/
|
||||
toString(options?: IStringOptions): string;
|
||||
/**
|
||||
* Returns the parent of this attribute.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var escape_1 = require("../escape");
|
||||
var options_1 = require("../options");
|
||||
var validate_1 = require("../validate");
|
||||
var XmlAttributeText_1 = __importDefault(require("./XmlAttributeText"));
|
||||
var XmlCharRef_1 = __importDefault(require("./XmlCharRef"));
|
||||
var XmlEntityRef_1 = __importDefault(require("./XmlEntityRef"));
|
||||
/**
|
||||
* Represents an attribute.
|
||||
*
|
||||
* An attribute is part of the start tag of an element and is
|
||||
* structured as follows, where `{name}` is the name of the attribute and
|
||||
* `{value}` is the value of the attribute:
|
||||
*
|
||||
* ```xml
|
||||
* <element {name}="{value}">
|
||||
* ```
|
||||
*
|
||||
* The `{name}` value is a property of this node, while the `{value}` property
|
||||
* consists of the children of this node.
|
||||
*
|
||||
* Attributes can have an unlimited number of attribute text, character
|
||||
* references, and entity references.
|
||||
*/
|
||||
var XmlAttribute = /** @class */ (function () {
|
||||
function XmlAttribute(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInName)) {
|
||||
this._replaceInvalidCharsInName = options.replaceInvalidCharsInName;
|
||||
}
|
||||
else {
|
||||
this._replaceInvalidCharsInName = false;
|
||||
}
|
||||
this._children = [];
|
||||
this._parent = parent;
|
||||
this.name = options.name;
|
||||
}
|
||||
Object.defineProperty(XmlAttribute.prototype, "name", {
|
||||
/**
|
||||
* Gets the name of this attribute.
|
||||
*/
|
||||
get: function () {
|
||||
return this._name;
|
||||
},
|
||||
/**
|
||||
* Sets the name of this attribute.
|
||||
*/
|
||||
set: function (name) {
|
||||
if (this._replaceInvalidCharsInName) {
|
||||
name = (0, validate_1.fixName)(name);
|
||||
if (name.length === 0) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": attribute name"
|
||||
+ " should not be empty");
|
||||
}
|
||||
}
|
||||
else if (this._validation && !(0, validate_1.validateName)(name)) {
|
||||
if (name.length === 0) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": attribute name"
|
||||
+ " should not be empty");
|
||||
}
|
||||
else {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": attribute name"
|
||||
+ (" \"" + name + "\" should not contain characters not")
|
||||
+ " allowed in XML names");
|
||||
}
|
||||
}
|
||||
this._name = name;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Adds a character reference to this attribute and returns the new
|
||||
* character reference.
|
||||
*/
|
||||
XmlAttribute.prototype.charRef = function (options) {
|
||||
var charRef = new XmlCharRef_1.default(this, this._validation, options);
|
||||
this._children.push(charRef);
|
||||
return charRef;
|
||||
};
|
||||
/**
|
||||
* Adds an entity reference to this attribute and returns the new entity
|
||||
* reference.
|
||||
*/
|
||||
XmlAttribute.prototype.entityRef = function (options) {
|
||||
var charRef = new XmlEntityRef_1.default(this, this._validation, options);
|
||||
this._children.push(charRef);
|
||||
return charRef;
|
||||
};
|
||||
/**
|
||||
* Adds attribute text to this attribute and returns the new text.
|
||||
*/
|
||||
XmlAttribute.prototype.text = function (options) {
|
||||
var textNode = new XmlAttributeText_1.default(this, this._validation, options);
|
||||
this._children.push(textNode);
|
||||
return textNode;
|
||||
};
|
||||
/**
|
||||
* Returns an XML string representation of this attribute.
|
||||
*/
|
||||
XmlAttribute.prototype.toString = function (options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var optionsObj = new options_1.StringOptions(options);
|
||||
var quote = optionsObj.doubleQuotes ? "\"" : "'";
|
||||
var str = this._name + "=" + quote;
|
||||
for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
|
||||
var child = _a[_i];
|
||||
if (optionsObj.doubleQuotes) {
|
||||
str += (0, escape_1.escapeDoubleQuotes)(child.toString());
|
||||
}
|
||||
else {
|
||||
str += (0, escape_1.escapeSingleQuotes)(child.toString());
|
||||
}
|
||||
}
|
||||
str += quote;
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this attribute.
|
||||
*/
|
||||
XmlAttribute.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlAttribute;
|
||||
}());
|
||||
exports.default = XmlAttribute;
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create attribute text.
|
||||
*/
|
||||
export interface IXmlAttributeTextOptions {
|
||||
/**
|
||||
* The attribute text.
|
||||
*/
|
||||
charData: string;
|
||||
/**
|
||||
* Whether to replace any invalid characters in the attribute text with the
|
||||
* Unicode replacement character. By default, this is disabled.
|
||||
*/
|
||||
replaceInvalidCharsInCharData?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents text in an attribute value.
|
||||
*
|
||||
* Restricted characters, such as the ampersand (`&`) and the opening angle
|
||||
* bracket (`<`), are all automatically escaped.
|
||||
*/
|
||||
export default class XmlAttributeText<Parent> {
|
||||
private readonly _replaceInvalidCharsInCharData;
|
||||
private readonly _parent;
|
||||
private readonly _validation;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlAttributeTextOptions);
|
||||
/**
|
||||
* Gets this attribute text.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets this attribute text.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this attribute text.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this attribute text.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var escape_1 = require("../escape");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents text in an attribute value.
|
||||
*
|
||||
* Restricted characters, such as the ampersand (`&`) and the opening angle
|
||||
* bracket (`<`), are all automatically escaped.
|
||||
*/
|
||||
var XmlAttributeText = /** @class */ (function () {
|
||||
function XmlAttributeText(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInCharData)) {
|
||||
this._replaceInvalidCharsInCharData = (options.replaceInvalidCharsInCharData);
|
||||
}
|
||||
else {
|
||||
this._replaceInvalidCharsInCharData = false;
|
||||
}
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlAttributeText.prototype, "charData", {
|
||||
/**
|
||||
* Gets this attribute text.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets this attribute text.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
charData = (0, validate_1.fixChar)(charData);
|
||||
}
|
||||
else if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": attribute text"
|
||||
+ (" \"" + charData + "\" should not contain characters not")
|
||||
+ " allowed in XML");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this attribute text.
|
||||
*/
|
||||
XmlAttributeText.prototype.toString = function () {
|
||||
var str = this._charData;
|
||||
str = (0, escape_1.escapeAmpersands)(str);
|
||||
str = (0, escape_1.escapeLeftAngleBrackets)(str);
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this attribute text.
|
||||
*/
|
||||
XmlAttributeText.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlAttributeText;
|
||||
}());
|
||||
exports.default = XmlAttributeText;
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a CDATA section.
|
||||
*/
|
||||
export interface IXmlCdataOptions {
|
||||
/**
|
||||
* The character data of the CDATA section.
|
||||
*/
|
||||
charData: string;
|
||||
/**
|
||||
* Whether to replace any invalid characters in the character data of the
|
||||
* CDATA section with the Unicode replacement character. By default, this
|
||||
* is disabled.
|
||||
*/
|
||||
replaceInvalidCharsInCharData?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents a CDATA section.
|
||||
*
|
||||
* A CDATA section is structured as follows, where `{data}` is the
|
||||
* character data of the section:
|
||||
*
|
||||
* ```xml
|
||||
* <![CDATA[{data}]]>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlCdata<Parent> {
|
||||
private readonly _replaceInvalidCharsInCharData;
|
||||
private readonly _parent;
|
||||
private readonly _validation;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlCdataOptions);
|
||||
/**
|
||||
* Gets the character data of this CDATA section.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the character data of this CDATA section.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this CDATA section.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this CDATA section.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a CDATA section.
|
||||
*
|
||||
* A CDATA section is structured as follows, where `{data}` is the
|
||||
* character data of the section:
|
||||
*
|
||||
* ```xml
|
||||
* <![CDATA[{data}]]>
|
||||
* ```
|
||||
*/
|
||||
var XmlCdata = /** @class */ (function () {
|
||||
function XmlCdata(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInCharData)) {
|
||||
this._replaceInvalidCharsInCharData = (options.replaceInvalidCharsInCharData);
|
||||
}
|
||||
else {
|
||||
this._replaceInvalidCharsInCharData = false;
|
||||
}
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlCdata.prototype, "charData", {
|
||||
/**
|
||||
* Gets the character data of this CDATA section.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the character data of this CDATA section.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
charData = (0, validate_1.fixChar)(charData);
|
||||
}
|
||||
else if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": CDATA section"
|
||||
+ (" \"" + charData + "\" should not contain characters")
|
||||
+ " not allowed in XML");
|
||||
}
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
charData = charData.replace("]]>", "\uFFFD\uFFFD\uFFFD");
|
||||
}
|
||||
else if (this._validation && charData.indexOf("]]>") !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": CDATA section"
|
||||
+ (" \"" + charData + "\" should not contain the string")
|
||||
+ " ']]>'");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this CDATA section.
|
||||
*/
|
||||
XmlCdata.prototype.toString = function () {
|
||||
return "<![CDATA[" + this._charData + "]]>";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this CDATA section.
|
||||
*/
|
||||
XmlCdata.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlCdata;
|
||||
}());
|
||||
exports.default = XmlCdata;
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create new character data.
|
||||
*/
|
||||
export interface IXmlCharDataOptions {
|
||||
/**
|
||||
* The character data.
|
||||
*/
|
||||
charData: string;
|
||||
/**
|
||||
* Whether to replace any invalid characters in the character data with the
|
||||
* Unicode replacement character. By default, this is disabled.
|
||||
*/
|
||||
replaceInvalidCharsInCharData?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents character data.
|
||||
*
|
||||
* Restricted characters, such as the ampersand (`&`), the opening angle
|
||||
* bracket (`<`), and the closing angle bracket (`>`) when it appears in the
|
||||
* string `]]>`, are all automatically escaped.
|
||||
*/
|
||||
export default class XmlCharData<Parent> {
|
||||
private readonly _replaceInvalidCharsInCharData;
|
||||
private readonly _parent;
|
||||
private readonly _validation;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlCharDataOptions);
|
||||
/**
|
||||
* Gets the text of this character data.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the text of this character data.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this character data.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this character data.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var escape_1 = require("../escape");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents character data.
|
||||
*
|
||||
* Restricted characters, such as the ampersand (`&`), the opening angle
|
||||
* bracket (`<`), and the closing angle bracket (`>`) when it appears in the
|
||||
* string `]]>`, are all automatically escaped.
|
||||
*/
|
||||
var XmlCharData = /** @class */ (function () {
|
||||
function XmlCharData(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInCharData)) {
|
||||
this._replaceInvalidCharsInCharData = (options.replaceInvalidCharsInCharData);
|
||||
}
|
||||
else {
|
||||
this._replaceInvalidCharsInCharData = false;
|
||||
}
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlCharData.prototype, "charData", {
|
||||
/**
|
||||
* Gets the text of this character data.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the text of this character data.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
charData = (0, validate_1.fixChar)(charData);
|
||||
}
|
||||
else if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": character data"
|
||||
+ ("\"" + charData + "\" should not contain characters not")
|
||||
+ " allowed in XML");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this character data.
|
||||
*/
|
||||
XmlCharData.prototype.toString = function () {
|
||||
var str = this._charData;
|
||||
str = (0, escape_1.escapeAmpersands)(str);
|
||||
str = (0, escape_1.escapeLeftAngleBrackets)(str);
|
||||
str = (0, escape_1.escapeRightAngleBracketsInCdataTerminator)(str);
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this character data.
|
||||
*/
|
||||
XmlCharData.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlCharData;
|
||||
}());
|
||||
exports.default = XmlCharData;
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new character reference.
|
||||
*/
|
||||
export interface IXmlCharRefOptions {
|
||||
/**
|
||||
* The character to represent using the reference.
|
||||
*/
|
||||
char: string;
|
||||
/**
|
||||
* Whether to use the hexadecimal or decimal representation for the
|
||||
* reference. Defaults to false.
|
||||
*/
|
||||
hex?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents a character reference.
|
||||
*
|
||||
* A character reference is structured as follows, where `{dec}` is the
|
||||
* decimal representation code point corresponding to a particular Unicode
|
||||
* character:
|
||||
*
|
||||
* ```xml
|
||||
* &#{dec};
|
||||
* ```
|
||||
*
|
||||
* The corresponding hexadecimal version is structured as follows, where
|
||||
* `{hex}` is the hexadecimal representation code point corresponding to a
|
||||
* particular Unicode character:
|
||||
*
|
||||
* ```xml
|
||||
* &#x{hex};
|
||||
* ```
|
||||
*
|
||||
* Unicode characters outside of the Basic Multilingual Plane are represented
|
||||
* using a surrogate pair consisting of two character references.
|
||||
*
|
||||
* The `{dec}` and `{hex}` values are defined by the `char` and `hex`
|
||||
* properties of this node; the former is the character to be represented while
|
||||
* the latter indicates whether the decimal or hexadecimal representation
|
||||
* should be used.
|
||||
*/
|
||||
export default class XmlCharRef<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _char;
|
||||
private _hex;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlCharRefOptions);
|
||||
/**
|
||||
* Gets the character of this character reference.
|
||||
*/
|
||||
get char(): string;
|
||||
/**
|
||||
* Sets the character of this character reference.
|
||||
*/
|
||||
set char(char: string);
|
||||
/**
|
||||
* Gets whether the decimal or hexadecimal representation should be used
|
||||
* for this character reference.
|
||||
*/
|
||||
get hex(): boolean;
|
||||
/**
|
||||
* Sets whether the decimal or hexadecimal representation should be used
|
||||
* for this character reference.
|
||||
*/
|
||||
set hex(hex: boolean);
|
||||
/**
|
||||
* Returns an XML string representation of this character reference.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this character reference.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a character reference.
|
||||
*
|
||||
* A character reference is structured as follows, where `{dec}` is the
|
||||
* decimal representation code point corresponding to a particular Unicode
|
||||
* character:
|
||||
*
|
||||
* ```xml
|
||||
* &#{dec};
|
||||
* ```
|
||||
*
|
||||
* The corresponding hexadecimal version is structured as follows, where
|
||||
* `{hex}` is the hexadecimal representation code point corresponding to a
|
||||
* particular Unicode character:
|
||||
*
|
||||
* ```xml
|
||||
* &#x{hex};
|
||||
* ```
|
||||
*
|
||||
* Unicode characters outside of the Basic Multilingual Plane are represented
|
||||
* using a surrogate pair consisting of two character references.
|
||||
*
|
||||
* The `{dec}` and `{hex}` values are defined by the `char` and `hex`
|
||||
* properties of this node; the former is the character to be represented while
|
||||
* the latter indicates whether the decimal or hexadecimal representation
|
||||
* should be used.
|
||||
*/
|
||||
var XmlCharRef = /** @class */ (function () {
|
||||
function XmlCharRef(parent, validation, options) {
|
||||
this._hex = false;
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.char = options.char;
|
||||
if (!(0, validate_1.isUndefined)(options.hex)) {
|
||||
this.hex = options.hex;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(XmlCharRef.prototype, "char", {
|
||||
/**
|
||||
* Gets the character of this character reference.
|
||||
*/
|
||||
get: function () {
|
||||
return this._char;
|
||||
},
|
||||
/**
|
||||
* Sets the character of this character reference.
|
||||
*/
|
||||
set: function (char) {
|
||||
if (this._validation && !(0, validate_1.validateSingleChar)(char)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": character reference"
|
||||
+ (" \"" + char + "\" should reference a single character,")
|
||||
+ " and this character should be allowed in XML");
|
||||
}
|
||||
this._char = char;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(XmlCharRef.prototype, "hex", {
|
||||
/**
|
||||
* Gets whether the decimal or hexadecimal representation should be used
|
||||
* for this character reference.
|
||||
*/
|
||||
get: function () {
|
||||
return this._hex;
|
||||
},
|
||||
/**
|
||||
* Sets whether the decimal or hexadecimal representation should be used
|
||||
* for this character reference.
|
||||
*/
|
||||
set: function (hex) {
|
||||
this._hex = hex;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this character reference.
|
||||
*/
|
||||
XmlCharRef.prototype.toString = function () {
|
||||
var char;
|
||||
if (this._char.length === 1) {
|
||||
char = this._char.charCodeAt(0);
|
||||
}
|
||||
else {
|
||||
var first = this._char.charCodeAt(0);
|
||||
if (first >= 0xD800 && first <= 0xDBFF && this._char.length > 1) {
|
||||
var second = this._char.charCodeAt(1);
|
||||
if (second >= 0xDC00 && second <= 0xDFFF) {
|
||||
char = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
||||
}
|
||||
else {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": character"
|
||||
+ (" reference \"" + this.char + "\" should")
|
||||
+ " reference a valid Unicode character");
|
||||
}
|
||||
}
|
||||
else {
|
||||
char = first;
|
||||
}
|
||||
}
|
||||
if (this._hex) {
|
||||
return "&#x" + char.toString(16) + ";";
|
||||
}
|
||||
else {
|
||||
return "&#" + char + ";";
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this character reference.
|
||||
*/
|
||||
XmlCharRef.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlCharRef;
|
||||
}());
|
||||
exports.default = XmlCharRef;
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new comment.
|
||||
*/
|
||||
export interface IXmlCommentOptions {
|
||||
/**
|
||||
* The content of the comment.
|
||||
*/
|
||||
charData: string;
|
||||
/**
|
||||
* Whether to replace any invalid characters in the content of the comment
|
||||
* with the Unicode replacement character. By default, this is disabled.
|
||||
*/
|
||||
replaceInvalidCharsInCharData?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents a comment.
|
||||
*
|
||||
* A comment is structured as follows, where `{content}` is the text of the
|
||||
* comment:
|
||||
*
|
||||
* ```xml
|
||||
* <!--{content}-->
|
||||
* ```
|
||||
*/
|
||||
export default class XmlComment<Parent> {
|
||||
private readonly _replaceInvalidCharsInCharData;
|
||||
private readonly _parent;
|
||||
private readonly _validation;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlCommentOptions);
|
||||
/**
|
||||
* Gets the text of this comment.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the text of this comment.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this comment.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this comment.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a comment.
|
||||
*
|
||||
* A comment is structured as follows, where `{content}` is the text of the
|
||||
* comment:
|
||||
*
|
||||
* ```xml
|
||||
* <!--{content}-->
|
||||
* ```
|
||||
*/
|
||||
var XmlComment = /** @class */ (function () {
|
||||
function XmlComment(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInCharData)) {
|
||||
this._replaceInvalidCharsInCharData = (options.replaceInvalidCharsInCharData);
|
||||
}
|
||||
else {
|
||||
this._replaceInvalidCharsInCharData = false;
|
||||
}
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlComment.prototype, "charData", {
|
||||
/**
|
||||
* Gets the text of this comment.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the text of this comment.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
charData = (0, validate_1.fixChar)(charData);
|
||||
}
|
||||
else if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": comment content"
|
||||
+ (" \"" + charData + "\" should not contain characters")
|
||||
+ " not allowed in XML");
|
||||
}
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
charData = charData.replace("--", "\uFFFD\uFFFD");
|
||||
}
|
||||
else if (this._validation && charData.indexOf("--") !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": comment content"
|
||||
+ (" \"" + charData + "\" should not contain the string")
|
||||
+ " '--'");
|
||||
}
|
||||
if (this._replaceInvalidCharsInCharData) {
|
||||
if (charData.lastIndexOf("-") === charData.length - 1) {
|
||||
charData = charData.substr(0, charData.length - 1) + "\uFFFD";
|
||||
}
|
||||
}
|
||||
else if (this._validation
|
||||
&& charData.lastIndexOf("-") === charData.length - 1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": comment content"
|
||||
+ (" \"" + charData + "\" should not end with the string")
|
||||
+ " '-'");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this comment.
|
||||
*/
|
||||
XmlComment.prototype.toString = function () {
|
||||
return "<!--" + this._charData + "-->";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this comment.
|
||||
*/
|
||||
XmlComment.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlComment;
|
||||
}());
|
||||
exports.default = XmlComment;
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IStringOptions } from "../options";
|
||||
/**
|
||||
* The options used to create a new declaration.
|
||||
*/
|
||||
export interface IXmlDeclOptions {
|
||||
/**
|
||||
* The encoding attribute to be included in the declaration. If defined,
|
||||
* this value must be a valid encoding. By default, no encoding attribute
|
||||
* is included.
|
||||
*/
|
||||
encoding?: string;
|
||||
/**
|
||||
* The value of the standalone attribute to be included in the declaration.
|
||||
* If defined, this value must be "yes" or "no". By default, no standalone
|
||||
* attribute is included.
|
||||
*/
|
||||
standalone?: string;
|
||||
/**
|
||||
* The XML version to be included in the declaration. If defined, this
|
||||
* value must be a valid XML version number. Defaults to "1.0".
|
||||
*/
|
||||
version?: string;
|
||||
}
|
||||
/**
|
||||
* Represents a declaration.
|
||||
*
|
||||
* A declaration is structured as follows, where `{version}` is the XML
|
||||
* version, `{encoding}` is the encoding of the document, and `{standalone}`
|
||||
* is either "yes" or "no", depending on whether the document may contain
|
||||
* external markup declarations:
|
||||
*
|
||||
* ```xml
|
||||
* <?xml version="{version}" encoding="{encoding}" standalone="{standalone}"?>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlDecl<Parent> {
|
||||
private readonly _validation;
|
||||
private _encoding;
|
||||
private readonly _parent;
|
||||
private _standalone;
|
||||
private _version;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDeclOptions);
|
||||
/**
|
||||
* Gets the encoding associated with this declaration.
|
||||
*/
|
||||
get encoding(): string | undefined;
|
||||
/**
|
||||
* Sets the encoding associated with this declaration.
|
||||
*/
|
||||
set encoding(encoding: string | undefined);
|
||||
/**
|
||||
* Gets the value of the standalone attribute associated with this
|
||||
* declaration.
|
||||
*/
|
||||
get standalone(): string | undefined;
|
||||
/**
|
||||
* Sets the value of the standalone attribute associated with this
|
||||
* declaration.
|
||||
*/
|
||||
set standalone(standalone: string | undefined);
|
||||
/**
|
||||
* Gets the XML version associated with this declaration.
|
||||
*/
|
||||
get version(): string;
|
||||
/**
|
||||
* Sets the XML version associated with this declaration.
|
||||
*/
|
||||
set version(version: string);
|
||||
/**
|
||||
* Returns an XML string representation of this declaration.
|
||||
*/
|
||||
toString(options?: IStringOptions): string;
|
||||
/**
|
||||
* Returns the parent of this declaration.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var options_1 = require("../options");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a declaration.
|
||||
*
|
||||
* A declaration is structured as follows, where `{version}` is the XML
|
||||
* version, `{encoding}` is the encoding of the document, and `{standalone}`
|
||||
* is either "yes" or "no", depending on whether the document may contain
|
||||
* external markup declarations:
|
||||
*
|
||||
* ```xml
|
||||
* <?xml version="{version}" encoding="{encoding}" standalone="{standalone}"?>
|
||||
* ```
|
||||
*/
|
||||
var XmlDecl = /** @class */ (function () {
|
||||
function XmlDecl(parent, validation, options) {
|
||||
this._version = "1.0";
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.encoding = options.encoding;
|
||||
this.standalone = options.standalone;
|
||||
if (!(0, validate_1.isUndefined)(options.version)) {
|
||||
this.version = options.version;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(XmlDecl.prototype, "encoding", {
|
||||
/**
|
||||
* Gets the encoding associated with this declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._encoding;
|
||||
},
|
||||
/**
|
||||
* Sets the encoding associated with this declaration.
|
||||
*/
|
||||
set: function (encoding) {
|
||||
if (this._validation && !(0, validate_1.isUndefined)(encoding)) {
|
||||
if (!validateEncoding(encoding)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": declaration"
|
||||
+ (" encoding attribute " + encoding + " should be a")
|
||||
+ " valid encoding");
|
||||
}
|
||||
}
|
||||
this._encoding = encoding;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(XmlDecl.prototype, "standalone", {
|
||||
/**
|
||||
* Gets the value of the standalone attribute associated with this
|
||||
* declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._standalone;
|
||||
},
|
||||
/**
|
||||
* Sets the value of the standalone attribute associated with this
|
||||
* declaration.
|
||||
*/
|
||||
set: function (standalone) {
|
||||
if (this._validation && !(0, validate_1.isUndefined)(standalone)) {
|
||||
if (standalone !== "yes" && standalone !== "no") {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": declaration"
|
||||
+ (" standalone attribute " + standalone + " should")
|
||||
+ " be the string 'yes' or the string 'no'");
|
||||
}
|
||||
}
|
||||
this._standalone = standalone;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(XmlDecl.prototype, "version", {
|
||||
/**
|
||||
* Gets the XML version associated with this declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._version;
|
||||
},
|
||||
/**
|
||||
* Sets the XML version associated with this declaration.
|
||||
*/
|
||||
set: function (version) {
|
||||
if (this._validation && !validateVersion(version)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": declaration version"
|
||||
+ (" attribute " + version + " should be a valid XML")
|
||||
+ " version");
|
||||
}
|
||||
this._version = version;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this declaration.
|
||||
*/
|
||||
XmlDecl.prototype.toString = function (options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var optionsObj = new options_1.StringOptions(options);
|
||||
var quote = optionsObj.doubleQuotes ? '"' : "'";
|
||||
var str = "<?xml version=" + quote + this._version + quote;
|
||||
if (!(0, validate_1.isUndefined)(this._encoding)) {
|
||||
str += " encoding=" + quote + this._encoding + quote;
|
||||
}
|
||||
if (!(0, validate_1.isUndefined)(this._standalone)) {
|
||||
str += " standalone=" + quote + this._standalone + quote;
|
||||
}
|
||||
str += "?>";
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this declaration.
|
||||
*/
|
||||
XmlDecl.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlDecl;
|
||||
}());
|
||||
exports.default = XmlDecl;
|
||||
/**
|
||||
* Returns true if the specified encoding only contains characters permitted by
|
||||
* the XML specification.
|
||||
*/
|
||||
function validateEncoding(str) {
|
||||
if (str.length === 0) {
|
||||
return false;
|
||||
}
|
||||
var initialChar = str.charCodeAt(0);
|
||||
if (!((initialChar >= 0x41 && initialChar <= 0x5A)
|
||||
|| (initialChar >= 0x61 && initialChar <= 0x7A))) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 1; i < str.length; i++) {
|
||||
var char = str.charCodeAt(i);
|
||||
if (char === 0x5F
|
||||
|| char === 0x2D
|
||||
|| char === 0x2E
|
||||
|| (char >= 0x30 && char <= 0x39)
|
||||
|| (char >= 0x41 && char <= 0x5A)
|
||||
|| (char >= 0x61 && char <= 0x7A)) {
|
||||
continue;
|
||||
}
|
||||
if (i + 1 === str.length) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Returns true if the specified version only contains characters permitted by
|
||||
* the XML specification.
|
||||
*/
|
||||
function validateVersion(str) {
|
||||
for (var i = 0; i <= 9; i++) {
|
||||
if (str === "1." + i) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IStringOptions } from "../options";
|
||||
import XmlComment, { IXmlCommentOptions } from "./XmlComment";
|
||||
import XmlDecl, { IXmlDeclOptions } from "./XmlDecl";
|
||||
import XmlDtd, { IXmlDtdOptions } from "./XmlDtd";
|
||||
import XmlElement, { IXmlElementOptions } from "./XmlElement";
|
||||
import XmlProcInst, { IXmlProcInstOptions } from "./XmlProcInst";
|
||||
/**
|
||||
* The options used to create a new document.
|
||||
*/
|
||||
export interface IXmlDocumentOptions {
|
||||
/**
|
||||
* Whether to throw an exception if basic XML validation fails while
|
||||
* building the document.
|
||||
*/
|
||||
validation?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents a document.
|
||||
*
|
||||
* A sample document is structured as follows:
|
||||
*
|
||||
* ```xml
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
* "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
* <html>
|
||||
* <head>
|
||||
* <title>My page title</title>
|
||||
* </head>
|
||||
* <body>
|
||||
* <h1>Welcome!</h1>
|
||||
* <p>I hope you enjoy visiting my website.</p>
|
||||
* <img src="picture.png"/>
|
||||
* </body>
|
||||
* </html>
|
||||
* ```
|
||||
*
|
||||
* Each component of the document, such as the declaration, document type
|
||||
* definition, and root element, are children of this node.
|
||||
*
|
||||
* Documents must have exactly one element, which is the document's root
|
||||
* element.
|
||||
*
|
||||
* Documents can have exactly one declaration and one document type definition
|
||||
* in that order, so long as they precede the element.
|
||||
*
|
||||
* Documents can have an unlimited number of comments or processing
|
||||
* instructions, so long as they follow the declaration, if one exists.
|
||||
*/
|
||||
export default class XmlDocument {
|
||||
private readonly _children;
|
||||
private readonly _validation;
|
||||
constructor(options: IXmlDocumentOptions);
|
||||
/**
|
||||
* Adds a comment to this document and returns the new comment.
|
||||
*/
|
||||
comment(options: IXmlCommentOptions): XmlComment<this>;
|
||||
/**
|
||||
* Adds a declaration to this document and returns the new declaration.
|
||||
*/
|
||||
decl(options?: IXmlDeclOptions): XmlDecl<this>;
|
||||
/**
|
||||
* Adds a document type definition to this document and returns the new
|
||||
* document type definition.
|
||||
*/
|
||||
dtd(options: IXmlDtdOptions): XmlDtd<this>;
|
||||
/**
|
||||
* Adds the root element to this document and returns the element.
|
||||
*/
|
||||
element(options: IXmlElementOptions): XmlElement<this>;
|
||||
/**
|
||||
* Adds a processing instruction to this document and returns the new
|
||||
* processing instruction.
|
||||
*/
|
||||
procInst(options: IXmlProcInstOptions): XmlProcInst<this>;
|
||||
/**
|
||||
* Returns an XML string representation of this document using the
|
||||
* specified options.
|
||||
*/
|
||||
toString(options?: IStringOptions): string;
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var options_1 = require("../options");
|
||||
var validate_1 = require("../validate");
|
||||
var XmlComment_1 = __importDefault(require("./XmlComment"));
|
||||
var XmlDecl_1 = __importDefault(require("./XmlDecl"));
|
||||
var XmlDtd_1 = __importDefault(require("./XmlDtd"));
|
||||
var XmlElement_1 = __importDefault(require("./XmlElement"));
|
||||
var XmlProcInst_1 = __importDefault(require("./XmlProcInst"));
|
||||
/**
|
||||
* Represents a document.
|
||||
*
|
||||
* A sample document is structured as follows:
|
||||
*
|
||||
* ```xml
|
||||
* <?xml version="1.0" encoding="UTF-8"?>
|
||||
* <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
* "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
* <html>
|
||||
* <head>
|
||||
* <title>My page title</title>
|
||||
* </head>
|
||||
* <body>
|
||||
* <h1>Welcome!</h1>
|
||||
* <p>I hope you enjoy visiting my website.</p>
|
||||
* <img src="picture.png"/>
|
||||
* </body>
|
||||
* </html>
|
||||
* ```
|
||||
*
|
||||
* Each component of the document, such as the declaration, document type
|
||||
* definition, and root element, are children of this node.
|
||||
*
|
||||
* Documents must have exactly one element, which is the document's root
|
||||
* element.
|
||||
*
|
||||
* Documents can have exactly one declaration and one document type definition
|
||||
* in that order, so long as they precede the element.
|
||||
*
|
||||
* Documents can have an unlimited number of comments or processing
|
||||
* instructions, so long as they follow the declaration, if one exists.
|
||||
*/
|
||||
var XmlDocument = /** @class */ (function () {
|
||||
function XmlDocument(options) {
|
||||
this._children = [];
|
||||
this._validation = !(0, validate_1.isUndefined)(options.validation)
|
||||
? options.validation
|
||||
: true;
|
||||
}
|
||||
/**
|
||||
* Adds a comment to this document and returns the new comment.
|
||||
*/
|
||||
XmlDocument.prototype.comment = function (options) {
|
||||
var comment = new XmlComment_1.default(this, this._validation, options);
|
||||
this._children.push(comment);
|
||||
return comment;
|
||||
};
|
||||
/**
|
||||
* Adds a declaration to this document and returns the new declaration.
|
||||
*/
|
||||
XmlDocument.prototype.decl = function (options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
if (this._validation && this._children.length !== 0) {
|
||||
throw new Error("in XML document: declaration must be the first"
|
||||
+ " child");
|
||||
}
|
||||
var declaration = new XmlDecl_1.default(this, this._validation, options);
|
||||
this._children.push(declaration);
|
||||
return declaration;
|
||||
};
|
||||
/**
|
||||
* Adds a document type definition to this document and returns the new
|
||||
* document type definition.
|
||||
*/
|
||||
XmlDocument.prototype.dtd = function (options) {
|
||||
var filteredChildren = this._children.filter(function (value) {
|
||||
return value instanceof XmlElement_1.default;
|
||||
});
|
||||
if (this._validation && filteredChildren.length !== 0) {
|
||||
throw new Error("in XML document: DTD must precede the root"
|
||||
+ " element");
|
||||
}
|
||||
var dtd = new XmlDtd_1.default(this, this._validation, options);
|
||||
this._children.push(dtd);
|
||||
return dtd;
|
||||
};
|
||||
/**
|
||||
* Adds the root element to this document and returns the element.
|
||||
*/
|
||||
XmlDocument.prototype.element = function (options) {
|
||||
var filteredChildren = this._children.filter(function (value) {
|
||||
return value instanceof XmlElement_1.default;
|
||||
});
|
||||
if (this._validation && filteredChildren.length !== 0) {
|
||||
throw new Error("in XML document: only one root element is"
|
||||
+ " permitted");
|
||||
}
|
||||
var element = new XmlElement_1.default(this, this._validation, options);
|
||||
this._children.push(element);
|
||||
return element;
|
||||
};
|
||||
/**
|
||||
* Adds a processing instruction to this document and returns the new
|
||||
* processing instruction.
|
||||
*/
|
||||
XmlDocument.prototype.procInst = function (options) {
|
||||
var procInst = new XmlProcInst_1.default(this, this._validation, options);
|
||||
this._children.push(procInst);
|
||||
return procInst;
|
||||
};
|
||||
/**
|
||||
* Returns an XML string representation of this document using the
|
||||
* specified options.
|
||||
*/
|
||||
XmlDocument.prototype.toString = function (options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var filteredChildren = this._children.filter(function (value) {
|
||||
return value instanceof XmlElement_1.default;
|
||||
});
|
||||
if (this._validation && filteredChildren.length !== 1) {
|
||||
throw new Error("in XML document: no more than one root element"
|
||||
+ " is permitted");
|
||||
}
|
||||
var optionsObj = new options_1.StringOptions(options);
|
||||
var str = "";
|
||||
for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
|
||||
var node = _a[_i];
|
||||
if (node instanceof XmlDecl_1.default
|
||||
|| node instanceof XmlDtd_1.default
|
||||
|| node instanceof XmlElement_1.default) {
|
||||
str += node.toString(options);
|
||||
}
|
||||
else {
|
||||
str += node.toString();
|
||||
}
|
||||
if (optionsObj.pretty) {
|
||||
str += optionsObj.newline;
|
||||
}
|
||||
}
|
||||
var len = str.length - optionsObj.newline.length;
|
||||
if (str.substr(len) === optionsObj.newline) {
|
||||
str = str.substr(0, len);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
return XmlDocument;
|
||||
}());
|
||||
exports.default = XmlDocument;
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IStringOptions } from "../options";
|
||||
import XmlComment, { IXmlCommentOptions } from "./XmlComment";
|
||||
import XmlDtdAttlist, { IXmlDtdAttlistOptions } from "./XmlDtdAttlist";
|
||||
import XmlDtdElement, { IXmlDtdElementOptions } from "./XmlDtdElement";
|
||||
import XmlDtdEntity, { IXmlDtdEntityOptions } from "./XmlDtdEntity";
|
||||
import XmlDtdNotation, { IXmlDtdNotationOptions } from "./XmlDtdNotation";
|
||||
import { default as XmlDtdParamEntityRef, IXmlDtdParamEntityRefOptions } from "./XmlDtdParamEntityRef";
|
||||
import XmlProcInst, { IXmlProcInstOptions } from "./XmlProcInst";
|
||||
/**
|
||||
* The options used to create a new document type definition.
|
||||
*/
|
||||
export interface IXmlDtdOptions {
|
||||
/**
|
||||
* The name of the DTD.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The system identifier of the DTD, excluding quotation marks. By default,
|
||||
* no system identifier is included.
|
||||
*/
|
||||
sysId?: string;
|
||||
/**
|
||||
* The public identifier of the DTD, excluding quotation marks. If a public
|
||||
* identifier is provided, a system identifier must be provided as well.
|
||||
* By default, no public identifier is included.
|
||||
*/
|
||||
pubId?: string;
|
||||
}
|
||||
/**
|
||||
* Represents an XML document type definition (DTD).
|
||||
*
|
||||
* A document type definition is structured as follows, where `{name}` is
|
||||
* the name of the DTD, `{sysId}` is the system identifier of the DTD,
|
||||
* `{pubId}` is the public identifier of the DTD, and `{intSubset}` is the
|
||||
* internal subset of the DTD:
|
||||
*
|
||||
* ```xml
|
||||
* <!DOCTYPE {name} SYSTEM "{sysId}" PUBLIC "{pubId}" [
|
||||
* {intSubset}
|
||||
* ]>
|
||||
* ```
|
||||
*
|
||||
* DTDs can have an unlimited number of comments, attribute-list declarations,
|
||||
* element declarations, entity declarations, notation declarations, parameter
|
||||
* entity references, and processing instructions.
|
||||
*/
|
||||
export default class XmlDtd<Parent> {
|
||||
private readonly _children;
|
||||
private readonly _parent;
|
||||
private _name;
|
||||
private readonly _validation;
|
||||
private _pubId;
|
||||
private _sysId;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDtdOptions);
|
||||
/**
|
||||
* Gets the name of the DTD.
|
||||
*/
|
||||
get name(): string;
|
||||
/**
|
||||
* Sets the name of the DTD.
|
||||
*/
|
||||
set name(name: string);
|
||||
/**
|
||||
* Gets the public identifier of the DTD.
|
||||
*/
|
||||
get pubId(): string | undefined;
|
||||
/**
|
||||
* Sets the public identifier of the DTD.
|
||||
*/
|
||||
set pubId(pubId: string | undefined);
|
||||
/**
|
||||
* Gets the system identifier of the DTD.
|
||||
*/
|
||||
get sysId(): string | undefined;
|
||||
/**
|
||||
* Sets the system identifier of the DTD.
|
||||
*/
|
||||
set sysId(sysId: string | undefined);
|
||||
/**
|
||||
* Adds an attribute-list declaration to this document type declaration
|
||||
* and returns the new attribute-list declaration.
|
||||
*/
|
||||
attlist(options: IXmlDtdAttlistOptions): XmlDtdAttlist<this>;
|
||||
/**
|
||||
* Adds a comment to this document type declaration and returns the
|
||||
* new comment.
|
||||
*/
|
||||
comment(options: IXmlCommentOptions): XmlComment<this>;
|
||||
/**
|
||||
* Adds an element declaration to this document type declaration
|
||||
* and returns the new element declaration.
|
||||
*/
|
||||
element(options: IXmlDtdElementOptions): XmlDtdElement<this>;
|
||||
/**
|
||||
* Adds an entity declaration to this document type declaration
|
||||
* and returns the new entity declaration.
|
||||
*/
|
||||
entity(options: IXmlDtdEntityOptions): XmlDtdEntity<this>;
|
||||
/**
|
||||
* Adds a notation declaration to this document type declaration
|
||||
* and returns the new notation declaration.
|
||||
*/
|
||||
notation(options: IXmlDtdNotationOptions): XmlDtdNotation<this>;
|
||||
/**
|
||||
* Adds a parameter entity reference to this document type declaration
|
||||
* and returns the new parameter entity reference.
|
||||
*/
|
||||
paramEntityRef(options: IXmlDtdParamEntityRefOptions): XmlDtdParamEntityRef<this>;
|
||||
/**
|
||||
* Adds a processing instruction to this document type declaration
|
||||
* and returns the new processing instruction.
|
||||
*/
|
||||
procInst(options: IXmlProcInstOptions): XmlProcInst<this>;
|
||||
/**
|
||||
* Returns an XML string representation of this document type declaration.
|
||||
*/
|
||||
toString(options?: IStringOptions): string;
|
||||
/**
|
||||
* Returns the parent of this attribute.
|
||||
*/
|
||||
up(): Parent;
|
||||
/**
|
||||
* Appends the XML string representation of a public or system identifier
|
||||
* to an existing string.
|
||||
*/
|
||||
private appendId;
|
||||
}
|
||||
/**
|
||||
* Returns true if the specified public identifier only contains characters
|
||||
* permitted by the XML specification.
|
||||
*/
|
||||
export declare function validatePubId(str: string): boolean;
|
||||
+312
@@ -0,0 +1,312 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.validatePubId = void 0;
|
||||
var error_1 = require("../error");
|
||||
var options_1 = require("../options");
|
||||
var validate_1 = require("../validate");
|
||||
var XmlComment_1 = __importDefault(require("./XmlComment"));
|
||||
var XmlDtdAttlist_1 = __importDefault(require("./XmlDtdAttlist"));
|
||||
var XmlDtdElement_1 = __importDefault(require("./XmlDtdElement"));
|
||||
var XmlDtdEntity_1 = __importDefault(require("./XmlDtdEntity"));
|
||||
var XmlDtdNotation_1 = __importDefault(require("./XmlDtdNotation"));
|
||||
var XmlDtdParamEntityRef_1 = __importDefault(require("./XmlDtdParamEntityRef"));
|
||||
var XmlProcInst_1 = __importDefault(require("./XmlProcInst"));
|
||||
/**
|
||||
* Represents an XML document type definition (DTD).
|
||||
*
|
||||
* A document type definition is structured as follows, where `{name}` is
|
||||
* the name of the DTD, `{sysId}` is the system identifier of the DTD,
|
||||
* `{pubId}` is the public identifier of the DTD, and `{intSubset}` is the
|
||||
* internal subset of the DTD:
|
||||
*
|
||||
* ```xml
|
||||
* <!DOCTYPE {name} SYSTEM "{sysId}" PUBLIC "{pubId}" [
|
||||
* {intSubset}
|
||||
* ]>
|
||||
* ```
|
||||
*
|
||||
* DTDs can have an unlimited number of comments, attribute-list declarations,
|
||||
* element declarations, entity declarations, notation declarations, parameter
|
||||
* entity references, and processing instructions.
|
||||
*/
|
||||
var XmlDtd = /** @class */ (function () {
|
||||
function XmlDtd(parent, validation, options) {
|
||||
this._pubId = undefined;
|
||||
this._sysId = undefined;
|
||||
this._validation = validation;
|
||||
this._children = [];
|
||||
this._parent = parent;
|
||||
this.name = options.name;
|
||||
if (!(0, validate_1.isUndefined)(options.sysId)) {
|
||||
this.sysId = options.sysId;
|
||||
}
|
||||
if (!(0, validate_1.isUndefined)(options.pubId)) {
|
||||
this.pubId = options.pubId;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(XmlDtd.prototype, "name", {
|
||||
/**
|
||||
* Gets the name of the DTD.
|
||||
*/
|
||||
get: function () {
|
||||
return this._name;
|
||||
},
|
||||
/**
|
||||
* Sets the name of the DTD.
|
||||
*/
|
||||
set: function (name) {
|
||||
if (this._validation && !(0, validate_1.validateName)(name)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": DTD name \"" + name + "\""
|
||||
+ " should not contain characters not allowed in"
|
||||
+ " XML names");
|
||||
}
|
||||
this._name = name;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(XmlDtd.prototype, "pubId", {
|
||||
/**
|
||||
* Gets the public identifier of the DTD.
|
||||
*/
|
||||
get: function () {
|
||||
return this._pubId;
|
||||
},
|
||||
/**
|
||||
* Sets the public identifier of the DTD.
|
||||
*/
|
||||
set: function (pubId) {
|
||||
if (!(0, validate_1.isUndefined)(pubId)) {
|
||||
if (this._validation && !validatePubId(pubId)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": DTD public"
|
||||
+ (" identifier \"" + pubId + "\" should not contain")
|
||||
+ " characters not allowed in public"
|
||||
+ " identifiers");
|
||||
}
|
||||
if (this._validation && (0, validate_1.isUndefined)(this._sysId)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": DTD public"
|
||||
+ (" identifier \"" + pubId + "\" should not be defined")
|
||||
+ " if system identifier is undefined");
|
||||
}
|
||||
}
|
||||
this._pubId = pubId;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(XmlDtd.prototype, "sysId", {
|
||||
/**
|
||||
* Gets the system identifier of the DTD.
|
||||
*/
|
||||
get: function () {
|
||||
return this._sysId;
|
||||
},
|
||||
/**
|
||||
* Sets the system identifier of the DTD.
|
||||
*/
|
||||
set: function (sysId) {
|
||||
if (!(0, validate_1.isUndefined)(sysId)) {
|
||||
if (this._validation && !(0, validate_1.validateChar)(sysId)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": DTD system"
|
||||
+ (" identifier \"" + sysId + "\" should not contain")
|
||||
+ " characters not allowed in XML");
|
||||
}
|
||||
else if (this._validation
|
||||
&& sysId.indexOf("'") !== -1
|
||||
&& sysId.indexOf("\"") !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": DTD system"
|
||||
+ (" identifier \"" + sysId + "\" should not contain")
|
||||
+ " both single quotes and double quotes");
|
||||
}
|
||||
}
|
||||
this._sysId = sysId;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Adds an attribute-list declaration to this document type declaration
|
||||
* and returns the new attribute-list declaration.
|
||||
*/
|
||||
XmlDtd.prototype.attlist = function (options) {
|
||||
var attlist = new XmlDtdAttlist_1.default(this, this._validation, options);
|
||||
this._children.push(attlist);
|
||||
return attlist;
|
||||
};
|
||||
/**
|
||||
* Adds a comment to this document type declaration and returns the
|
||||
* new comment.
|
||||
*/
|
||||
XmlDtd.prototype.comment = function (options) {
|
||||
var comment = new XmlComment_1.default(this, this._validation, options);
|
||||
this._children.push(comment);
|
||||
return comment;
|
||||
};
|
||||
/**
|
||||
* Adds an element declaration to this document type declaration
|
||||
* and returns the new element declaration.
|
||||
*/
|
||||
XmlDtd.prototype.element = function (options) {
|
||||
var element = new XmlDtdElement_1.default(this, this._validation, options);
|
||||
this._children.push(element);
|
||||
return element;
|
||||
};
|
||||
/**
|
||||
* Adds an entity declaration to this document type declaration
|
||||
* and returns the new entity declaration.
|
||||
*/
|
||||
XmlDtd.prototype.entity = function (options) {
|
||||
var entity = new XmlDtdEntity_1.default(this, this._validation, options);
|
||||
this._children.push(entity);
|
||||
return entity;
|
||||
};
|
||||
/**
|
||||
* Adds a notation declaration to this document type declaration
|
||||
* and returns the new notation declaration.
|
||||
*/
|
||||
XmlDtd.prototype.notation = function (options) {
|
||||
var notation = new XmlDtdNotation_1.default(this, this._validation, options);
|
||||
this._children.push(notation);
|
||||
return notation;
|
||||
};
|
||||
/**
|
||||
* Adds a parameter entity reference to this document type declaration
|
||||
* and returns the new parameter entity reference.
|
||||
*/
|
||||
XmlDtd.prototype.paramEntityRef = function (options) {
|
||||
var paramEntity = new XmlDtdParamEntityRef_1.default(this, this._validation, options);
|
||||
this._children.push(paramEntity);
|
||||
return paramEntity;
|
||||
};
|
||||
/**
|
||||
* Adds a processing instruction to this document type declaration
|
||||
* and returns the new processing instruction.
|
||||
*/
|
||||
XmlDtd.prototype.procInst = function (options) {
|
||||
var procInst = new XmlProcInst_1.default(this, this._validation, options);
|
||||
this._children.push(procInst);
|
||||
return procInst;
|
||||
};
|
||||
/**
|
||||
* Returns an XML string representation of this document type declaration.
|
||||
*/
|
||||
XmlDtd.prototype.toString = function (options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var optionsObj = new options_1.StringOptions(options);
|
||||
var str = "<!DOCTYPE " + this._name;
|
||||
if ((0, validate_1.isUndefined)(this._pubId)) {
|
||||
if (!(0, validate_1.isUndefined)(this._sysId)) {
|
||||
str += " ";
|
||||
str = this.appendId("SYSTEM", this._sysId, str, optionsObj);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((0, validate_1.isUndefined)(this._sysId)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": DTD system"
|
||||
+ " identifier is not undefined");
|
||||
}
|
||||
str += " ";
|
||||
str = this.appendId("PUBLIC", this._pubId, str, optionsObj);
|
||||
str = this.appendId("", this._sysId, str, optionsObj);
|
||||
}
|
||||
if (this._children.length !== 0) {
|
||||
str += " [";
|
||||
for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
|
||||
var node = _a[_i];
|
||||
if (optionsObj.pretty) {
|
||||
str += optionsObj.newline + optionsObj.indent;
|
||||
}
|
||||
str += node.toString();
|
||||
}
|
||||
if (optionsObj.pretty) {
|
||||
str += optionsObj.newline;
|
||||
}
|
||||
str += "]>";
|
||||
}
|
||||
else {
|
||||
str += ">";
|
||||
}
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this attribute.
|
||||
*/
|
||||
XmlDtd.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
/**
|
||||
* Appends the XML string representation of a public or system identifier
|
||||
* to an existing string.
|
||||
*/
|
||||
XmlDtd.prototype.appendId = function (type, value, str, options) {
|
||||
str += type + " ";
|
||||
if (options.doubleQuotes) {
|
||||
if (this._validation && value.indexOf("\"") !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": doubleQuotes option"
|
||||
+ " inconsistent with DTD system identifier or"
|
||||
+ " public identifier");
|
||||
}
|
||||
str += "\"" + value + "\"";
|
||||
}
|
||||
else {
|
||||
if (this._validation && value.indexOf("'") !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this) + ": doubleQuotes option"
|
||||
+ " inconsistent with DTD system identifier or"
|
||||
+ " public identifier");
|
||||
}
|
||||
str += "'" + value + "'";
|
||||
}
|
||||
return str;
|
||||
};
|
||||
return XmlDtd;
|
||||
}());
|
||||
exports.default = XmlDtd;
|
||||
/**
|
||||
* Returns true if the specified public identifier only contains characters
|
||||
* permitted by the XML specification.
|
||||
*/
|
||||
function validatePubId(str) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var char = str.charCodeAt(i);
|
||||
if (char === 0xA
|
||||
|| char === 0xD
|
||||
|| char === 0x20
|
||||
|| char === 0x21
|
||||
|| (char >= 0x23 && char <= 0x25)
|
||||
|| (char >= 0x27 && char <= 0x2F)
|
||||
|| (char >= 0x30 && char <= 0x39)
|
||||
|| char === 0x3A
|
||||
|| char === 0x3B
|
||||
|| char === 0x3D
|
||||
|| char === 0x3F
|
||||
|| (char >= 0x40 && char <= 0x5A)
|
||||
|| char === 0x5F
|
||||
|| (char >= 0x61 && char <= 0x7A)) {
|
||||
continue;
|
||||
}
|
||||
if (i + 1 === str.length) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.validatePubId = validatePubId;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new attribute-list declaration.
|
||||
*/
|
||||
export interface IXmlDtdAttlistOptions {
|
||||
/**
|
||||
* The text of the declaration.
|
||||
*/
|
||||
charData: string;
|
||||
}
|
||||
/**
|
||||
* Represents an attribute-list declaration in a document type definition.
|
||||
*
|
||||
* An attribute-list declaration is structured as follows, where `{text}`
|
||||
* is the text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!ATTLIST {text}>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlDtdAttlist<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDtdAttlistOptions);
|
||||
/**
|
||||
* Gets the text of this entity declaration.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the text of this entity declaration.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this entity declaration.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this entity declaration.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents an attribute-list declaration in a document type definition.
|
||||
*
|
||||
* An attribute-list declaration is structured as follows, where `{text}`
|
||||
* is the text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!ATTLIST {text}>
|
||||
* ```
|
||||
*/
|
||||
var XmlDtdAttlist = /** @class */ (function () {
|
||||
function XmlDtdAttlist(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlDtdAttlist.prototype, "charData", {
|
||||
/**
|
||||
* Gets the text of this entity declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the text of this entity declaration.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": attribute-list"
|
||||
+ (" declaration \"" + charData + "\" should not contain")
|
||||
+ " characters not allowed in XML");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this entity declaration.
|
||||
*/
|
||||
XmlDtdAttlist.prototype.toString = function () {
|
||||
return "<!ATTLIST " + this._charData + ">";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this entity declaration.
|
||||
*/
|
||||
XmlDtdAttlist.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlDtdAttlist;
|
||||
}());
|
||||
exports.default = XmlDtdAttlist;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new element declaration.
|
||||
*/
|
||||
export interface IXmlDtdElementOptions {
|
||||
/**
|
||||
* The text of the declaration.
|
||||
*/
|
||||
charData: string;
|
||||
}
|
||||
/**
|
||||
* Represents an element declaration in a document type definition.
|
||||
*
|
||||
* An element declaration is structured as follows, where `{text}` is the
|
||||
* text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!ELEMENT {text}>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlDtdElement<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDtdElementOptions);
|
||||
/**
|
||||
* Gets the text of this element declaration.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the text of this element declaration.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this element declaration.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this element declaration.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents an element declaration in a document type definition.
|
||||
*
|
||||
* An element declaration is structured as follows, where `{text}` is the
|
||||
* text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!ELEMENT {text}>
|
||||
* ```
|
||||
*/
|
||||
var XmlDtdElement = /** @class */ (function () {
|
||||
function XmlDtdElement(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlDtdElement.prototype, "charData", {
|
||||
/**
|
||||
* Gets the text of this element declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the text of this element declaration.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": element declaration"
|
||||
+ (" \"" + charData + "\" should not contain characters")
|
||||
+ " not allowed in XML");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this element declaration.
|
||||
*/
|
||||
XmlDtdElement.prototype.toString = function () {
|
||||
return "<!ELEMENT " + this._charData + ">";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this element declaration.
|
||||
*/
|
||||
XmlDtdElement.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlDtdElement;
|
||||
}());
|
||||
exports.default = XmlDtdElement;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new entity declaration.
|
||||
*/
|
||||
export interface IXmlDtdEntityOptions {
|
||||
/**
|
||||
* The text of the declaration.
|
||||
*/
|
||||
charData: string;
|
||||
}
|
||||
/**
|
||||
* Represents an entity declaration in a document type definition.
|
||||
*
|
||||
* An entity declaration is structured as follows, where `{text}` is the
|
||||
* text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!ENTITY {text}>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlDtdEntity<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDtdEntityOptions);
|
||||
/**
|
||||
* Gets the text of this entity declaration.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the text of this entity declaration.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this entity declaration.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this entity declaration.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents an entity declaration in a document type definition.
|
||||
*
|
||||
* An entity declaration is structured as follows, where `{text}` is the
|
||||
* text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!ENTITY {text}>
|
||||
* ```
|
||||
*/
|
||||
var XmlDtdEntity = /** @class */ (function () {
|
||||
function XmlDtdEntity(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlDtdEntity.prototype, "charData", {
|
||||
/**
|
||||
* Gets the text of this entity declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the text of this entity declaration.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": entity declaration"
|
||||
+ (" \"" + charData + "\" should not contain characters")
|
||||
+ " not allowed in XML");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this entity declaration.
|
||||
*/
|
||||
XmlDtdEntity.prototype.toString = function () {
|
||||
return "<!ENTITY " + this._charData + ">";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this entity declaration.
|
||||
*/
|
||||
XmlDtdEntity.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlDtdEntity;
|
||||
}());
|
||||
exports.default = XmlDtdEntity;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new notation declaration.
|
||||
*/
|
||||
export interface IXmlDtdNotationOptions {
|
||||
/**
|
||||
* The text of the declaration.
|
||||
*/
|
||||
charData: string;
|
||||
}
|
||||
/**
|
||||
* Represents a notation declaration in a document type definition.
|
||||
*
|
||||
* A notation declaration is structured as follows, where `{text}` is the
|
||||
* text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!NOTATION {text}>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlDtdNotation<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _charData;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDtdNotationOptions);
|
||||
/**
|
||||
* Gets the text of this notation declaration.
|
||||
*/
|
||||
get charData(): string;
|
||||
/**
|
||||
* Sets the text of this notation declaration.
|
||||
*/
|
||||
set charData(charData: string);
|
||||
/**
|
||||
* Returns an XML string representation of this notation declaration.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this notation declaration.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a notation declaration in a document type definition.
|
||||
*
|
||||
* A notation declaration is structured as follows, where `{text}` is the
|
||||
* text of the declaration:
|
||||
*
|
||||
* ```xml
|
||||
* <!NOTATION {text}>
|
||||
* ```
|
||||
*/
|
||||
var XmlDtdNotation = /** @class */ (function () {
|
||||
function XmlDtdNotation(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.charData = options.charData;
|
||||
}
|
||||
Object.defineProperty(XmlDtdNotation.prototype, "charData", {
|
||||
/**
|
||||
* Gets the text of this notation declaration.
|
||||
*/
|
||||
get: function () {
|
||||
return this._charData;
|
||||
},
|
||||
/**
|
||||
* Sets the text of this notation declaration.
|
||||
*/
|
||||
set: function (charData) {
|
||||
if (this._validation && !(0, validate_1.validateChar)(charData)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": notation declaration"
|
||||
+ (" \"" + charData + "\" should not contain characters")
|
||||
+ " not allowed in XML");
|
||||
}
|
||||
this._charData = charData;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this notation declaration.
|
||||
*/
|
||||
XmlDtdNotation.prototype.toString = function () {
|
||||
return "<!NOTATION " + this._charData + ">";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this notation declaration.
|
||||
*/
|
||||
XmlDtdNotation.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlDtdNotation;
|
||||
}());
|
||||
exports.default = XmlDtdNotation;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new parameter entity reference.
|
||||
*/
|
||||
export interface IXmlDtdParamEntityRefOptions {
|
||||
/**
|
||||
* The name of the entity to be referenced.
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Represents a parameter entity reference in a document type definition.
|
||||
*
|
||||
* A parameter entity reference is structured as follows, where `{entity}`
|
||||
* is the name of the entity:
|
||||
*
|
||||
* ```xml
|
||||
* %{entity};
|
||||
* ```
|
||||
*/
|
||||
export default class XmlDtdParamEntityRef<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _name;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlDtdParamEntityRefOptions);
|
||||
/**
|
||||
* Gets the name of this parameter entity reference.
|
||||
*/
|
||||
get name(): string;
|
||||
/**
|
||||
* Sets the name of this parameter entity reference.
|
||||
*/
|
||||
set name(name: string);
|
||||
/**
|
||||
* Returns an XML string representation of this parameter entity reference.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this parameter entity reference.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a parameter entity reference in a document type definition.
|
||||
*
|
||||
* A parameter entity reference is structured as follows, where `{entity}`
|
||||
* is the name of the entity:
|
||||
*
|
||||
* ```xml
|
||||
* %{entity};
|
||||
* ```
|
||||
*/
|
||||
var XmlDtdParamEntityRef = /** @class */ (function () {
|
||||
function XmlDtdParamEntityRef(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.name = options.name;
|
||||
}
|
||||
Object.defineProperty(XmlDtdParamEntityRef.prototype, "name", {
|
||||
/**
|
||||
* Gets the name of this parameter entity reference.
|
||||
*/
|
||||
get: function () {
|
||||
return this._name;
|
||||
},
|
||||
/**
|
||||
* Sets the name of this parameter entity reference.
|
||||
*/
|
||||
set: function (name) {
|
||||
if (this._validation && !(0, validate_1.validateName)(name)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": parameter entity"
|
||||
+ (" reference name \"" + name + "\" should not contain")
|
||||
+ " characters not allowed in XML names");
|
||||
}
|
||||
this._name = name;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this parameter entity reference.
|
||||
*/
|
||||
XmlDtdParamEntityRef.prototype.toString = function () {
|
||||
return "%" + this._name + ";";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this parameter entity reference.
|
||||
*/
|
||||
XmlDtdParamEntityRef.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlDtdParamEntityRef;
|
||||
}());
|
||||
exports.default = XmlDtdParamEntityRef;
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IStringOptions } from "../options";
|
||||
import { default as XmlAttribute, IXmlAttributeOptions as IXmlAttributeOptions } from "./XmlAttribute";
|
||||
import XmlCdata, { IXmlCdataOptions } from "./XmlCdata";
|
||||
import XmlCharData, { IXmlCharDataOptions } from "./XmlCharData";
|
||||
import XmlCharRef, { IXmlCharRefOptions } from "./XmlCharRef";
|
||||
import XmlComment, { IXmlCommentOptions } from "./XmlComment";
|
||||
import XmlEntityRef, { IXmlEntityRefOptions } from "./XmlEntityRef";
|
||||
import XmlProcInst, { IXmlProcInstOptions } from "./XmlProcInst";
|
||||
/**
|
||||
* The options used to create a new element.
|
||||
*/
|
||||
export interface IXmlElementOptions {
|
||||
/**
|
||||
* The name of the element.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Whether to replace any invalid characters in the name of the element
|
||||
* with the Unicode replacement character. By default, this is disabled.
|
||||
*/
|
||||
replaceInvalidCharsInName?: boolean;
|
||||
/**
|
||||
* Whether to use a self-closing tag if this element is empty.
|
||||
*
|
||||
* For example, use:
|
||||
* ```xml
|
||||
* <element/>
|
||||
* ```
|
||||
* instead of:
|
||||
* ```xml
|
||||
* <element></element>
|
||||
* ```
|
||||
*
|
||||
* By default, this is enabled.
|
||||
*/
|
||||
useSelfClosingTagIfEmpty?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents an XML element.
|
||||
*
|
||||
* A sample element is structured as follows, where `{name}` is the name
|
||||
* of the element:
|
||||
*
|
||||
* ```xml
|
||||
* <{name} attname="attvalue">
|
||||
* <subelem/>
|
||||
* <?pitarget picontent?>
|
||||
* text
|
||||
* </{name}></pre>
|
||||
* ```
|
||||
*
|
||||
* XML elements can have an unlimited number of attributes, CDATA sections,
|
||||
* character references, comments, elements, entity references, processing
|
||||
* instructions, and character data.
|
||||
*
|
||||
* An element with no content will be represented using an empty element tag:
|
||||
*
|
||||
* ```xml
|
||||
* <{name}/>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlElement<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _children;
|
||||
private readonly _attributeNames;
|
||||
private readonly _parent;
|
||||
private readonly _replaceInvalidCharsInName;
|
||||
private readonly _useSelfClosingTagIfEmpty;
|
||||
private _name;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlElementOptions);
|
||||
/**
|
||||
* Gets the name of this element.
|
||||
*/
|
||||
get name(): string;
|
||||
/**
|
||||
* Sets the name of this element.
|
||||
*/
|
||||
set name(name: string);
|
||||
/**
|
||||
* Adds an attribute to this element and returns the new attribute.
|
||||
*/
|
||||
attribute(options: IXmlAttributeOptions): XmlAttribute<this>;
|
||||
/**
|
||||
* Adds a CDATA section to this element and returns the new CDATA section.
|
||||
*/
|
||||
cdata(options: IXmlCdataOptions): XmlCdata<this>;
|
||||
/**
|
||||
* Adds character data to this element and returns the new character data.
|
||||
*/
|
||||
charData(options: IXmlCharDataOptions): XmlCharData<this>;
|
||||
/**
|
||||
* Adds a character reference to this element and returns the new
|
||||
* character reference.
|
||||
*/
|
||||
charRef(options: IXmlCharRefOptions): XmlCharRef<this>;
|
||||
/**
|
||||
* Adds a comment to this element and returns the new comment.
|
||||
*/
|
||||
comment(options: IXmlCommentOptions): XmlComment<this>;
|
||||
/**
|
||||
* Adds an element to this element and returns the new element.
|
||||
*/
|
||||
element(options: IXmlElementOptions): XmlElement<this>;
|
||||
/**
|
||||
* Adds an entity reference to this element and returns the new entity
|
||||
* reference.
|
||||
*/
|
||||
entityRef(options: IXmlEntityRefOptions): XmlEntityRef<this>;
|
||||
/**
|
||||
* Adds a processing instruction to this element and returns the new
|
||||
* processing instruction.
|
||||
*/
|
||||
procInst(options: IXmlProcInstOptions): XmlProcInst<this>;
|
||||
/**
|
||||
* Returns an XML string representation of this element using the specified
|
||||
* options.
|
||||
*/
|
||||
toString(options?: IStringOptions): string;
|
||||
/**
|
||||
* Returns the parent of this element.
|
||||
*/
|
||||
up(): Parent;
|
||||
/**
|
||||
* Returns an XML string representation of this element using the specified
|
||||
* options and initial indent.
|
||||
*/
|
||||
private toStringWithIndent;
|
||||
/**
|
||||
* Returns true if the specified nodes are all character references,
|
||||
* entity references, or character data.
|
||||
*/
|
||||
private allSameLineNodes;
|
||||
/**
|
||||
* Returns true if the specified nodes are all character references,
|
||||
* entity references, or character data.
|
||||
*/
|
||||
private onSameLine;
|
||||
}
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var options_1 = require("../options");
|
||||
var validate_1 = require("../validate");
|
||||
var XmlAttribute_1 = __importDefault(require("./XmlAttribute"));
|
||||
var XmlCdata_1 = __importDefault(require("./XmlCdata"));
|
||||
var XmlCharData_1 = __importDefault(require("./XmlCharData"));
|
||||
var XmlCharRef_1 = __importDefault(require("./XmlCharRef"));
|
||||
var XmlComment_1 = __importDefault(require("./XmlComment"));
|
||||
var XmlEntityRef_1 = __importDefault(require("./XmlEntityRef"));
|
||||
var XmlProcInst_1 = __importDefault(require("./XmlProcInst"));
|
||||
/**
|
||||
* Represents an XML element.
|
||||
*
|
||||
* A sample element is structured as follows, where `{name}` is the name
|
||||
* of the element:
|
||||
*
|
||||
* ```xml
|
||||
* <{name} attname="attvalue">
|
||||
* <subelem/>
|
||||
* <?pitarget picontent?>
|
||||
* text
|
||||
* </{name}></pre>
|
||||
* ```
|
||||
*
|
||||
* XML elements can have an unlimited number of attributes, CDATA sections,
|
||||
* character references, comments, elements, entity references, processing
|
||||
* instructions, and character data.
|
||||
*
|
||||
* An element with no content will be represented using an empty element tag:
|
||||
*
|
||||
* ```xml
|
||||
* <{name}/>
|
||||
* ```
|
||||
*/
|
||||
var XmlElement = /** @class */ (function () {
|
||||
function XmlElement(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
if (!(0, validate_1.isUndefined)(options.replaceInvalidCharsInName)) {
|
||||
this._replaceInvalidCharsInName = options.replaceInvalidCharsInName;
|
||||
}
|
||||
else {
|
||||
this._replaceInvalidCharsInName = false;
|
||||
}
|
||||
if (!(0, validate_1.isUndefined)(options.useSelfClosingTagIfEmpty)) {
|
||||
this._useSelfClosingTagIfEmpty = options.useSelfClosingTagIfEmpty;
|
||||
}
|
||||
else {
|
||||
this._useSelfClosingTagIfEmpty = true;
|
||||
}
|
||||
this._children = [];
|
||||
this._attributeNames = [];
|
||||
this._parent = parent;
|
||||
this.name = options.name;
|
||||
}
|
||||
Object.defineProperty(XmlElement.prototype, "name", {
|
||||
/**
|
||||
* Gets the name of this element.
|
||||
*/
|
||||
get: function () {
|
||||
return this._name;
|
||||
},
|
||||
/**
|
||||
* Sets the name of this element.
|
||||
*/
|
||||
set: function (name) {
|
||||
if (this._replaceInvalidCharsInName) {
|
||||
name = (0, validate_1.fixName)(name);
|
||||
if (name.length === 0) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": element name should"
|
||||
+ " not be empty");
|
||||
}
|
||||
}
|
||||
else if (this._validation && !(0, validate_1.validateName)(name)) {
|
||||
if (name.length === 0) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": element name should"
|
||||
+ " not be empty");
|
||||
}
|
||||
else {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": element name"
|
||||
+ (" \"" + name + "\" should not contain characters not")
|
||||
+ " allowed in XML names");
|
||||
}
|
||||
}
|
||||
this._name = name;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Adds an attribute to this element and returns the new attribute.
|
||||
*/
|
||||
XmlElement.prototype.attribute = function (options) {
|
||||
if (this._validation
|
||||
&& this._attributeNames.indexOf(options.name) !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": element \"" + this.name + "\""
|
||||
+ " already contains an attribute with the"
|
||||
+ (" name \"" + options.name + "\""));
|
||||
}
|
||||
var attribute = new XmlAttribute_1.default(this, this._validation, options);
|
||||
this._children.push(attribute);
|
||||
this._attributeNames.push(options.name);
|
||||
return attribute;
|
||||
};
|
||||
/**
|
||||
* Adds a CDATA section to this element and returns the new CDATA section.
|
||||
*/
|
||||
XmlElement.prototype.cdata = function (options) {
|
||||
var cdata = new XmlCdata_1.default(this, this._validation, options);
|
||||
this._children.push(cdata);
|
||||
return cdata;
|
||||
};
|
||||
/**
|
||||
* Adds character data to this element and returns the new character data.
|
||||
*/
|
||||
XmlElement.prototype.charData = function (options) {
|
||||
var charDataNode = new XmlCharData_1.default(this, this._validation, options);
|
||||
this._children.push(charDataNode);
|
||||
return charDataNode;
|
||||
};
|
||||
/**
|
||||
* Adds a character reference to this element and returns the new
|
||||
* character reference.
|
||||
*/
|
||||
XmlElement.prototype.charRef = function (options) {
|
||||
var charRef = new XmlCharRef_1.default(this, this._validation, options);
|
||||
this._children.push(charRef);
|
||||
return charRef;
|
||||
};
|
||||
/**
|
||||
* Adds a comment to this element and returns the new comment.
|
||||
*/
|
||||
XmlElement.prototype.comment = function (options) {
|
||||
var comment = new XmlComment_1.default(this, this._validation, options);
|
||||
this._children.push(comment);
|
||||
return comment;
|
||||
};
|
||||
/**
|
||||
* Adds an element to this element and returns the new element.
|
||||
*/
|
||||
XmlElement.prototype.element = function (options) {
|
||||
var element = new XmlElement(this, this._validation, options);
|
||||
this._children.push(element);
|
||||
return element;
|
||||
};
|
||||
/**
|
||||
* Adds an entity reference to this element and returns the new entity
|
||||
* reference.
|
||||
*/
|
||||
XmlElement.prototype.entityRef = function (options) {
|
||||
var entityRef = new XmlEntityRef_1.default(this, this._validation, options);
|
||||
this._children.push(entityRef);
|
||||
return entityRef;
|
||||
};
|
||||
/**
|
||||
* Adds a processing instruction to this element and returns the new
|
||||
* processing instruction.
|
||||
*/
|
||||
XmlElement.prototype.procInst = function (options) {
|
||||
var procInst = new XmlProcInst_1.default(this, this._validation, options);
|
||||
this._children.push(procInst);
|
||||
return procInst;
|
||||
};
|
||||
/**
|
||||
* Returns an XML string representation of this element using the specified
|
||||
* options.
|
||||
*/
|
||||
XmlElement.prototype.toString = function (options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return this.toStringWithIndent(options, "");
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this element.
|
||||
*/
|
||||
XmlElement.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
/**
|
||||
* Returns an XML string representation of this element using the specified
|
||||
* options and initial indent.
|
||||
*/
|
||||
XmlElement.prototype.toStringWithIndent = function (options, indent) {
|
||||
var optionsObj = new options_1.StringOptions(options);
|
||||
var newIndent = indent + optionsObj.indent;
|
||||
// Element tag start
|
||||
var str = "<" + this._name;
|
||||
// Attributes and other nodes
|
||||
var nodes = [];
|
||||
for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
|
||||
var node = _a[_i];
|
||||
if (node instanceof XmlAttribute_1.default) {
|
||||
str += " " + node.toString(options);
|
||||
}
|
||||
else {
|
||||
nodes.push(node);
|
||||
}
|
||||
}
|
||||
// Child nodes
|
||||
if (nodes.length > 0) {
|
||||
var childStr = "";
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var next = nodes[i];
|
||||
var nextStr = "";
|
||||
if (next instanceof XmlElement) {
|
||||
nextStr += next.toStringWithIndent(optionsObj, newIndent);
|
||||
}
|
||||
else {
|
||||
nextStr += next.toString();
|
||||
}
|
||||
var prev = i > 0 ? nodes[i - 1] : undefined;
|
||||
// Skip empty nodes
|
||||
if (next instanceof XmlCharData_1.default && next.toString() === "") {
|
||||
continue;
|
||||
}
|
||||
// Line break before child nodes unless all nodes, or at least
|
||||
// the most recent two, are of type XmlCharacterReference,
|
||||
// XmlEntityReference, or XmlCharData
|
||||
if (optionsObj.pretty) {
|
||||
if (!this.allSameLineNodes(nodes)) {
|
||||
if (!(i > 0 && this.onSameLine(next, prev))) {
|
||||
nextStr = optionsObj.newline + newIndent + nextStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
childStr += nextStr;
|
||||
}
|
||||
// Line break before end tag unless all nodes are of type
|
||||
// XmlCharacterReference, XmlEntityReference, or XmlCharData
|
||||
if (optionsObj.pretty) {
|
||||
if (!this.allSameLineNodes(nodes)) {
|
||||
childStr += optionsObj.newline + indent;
|
||||
}
|
||||
}
|
||||
if (childStr.length === 0 && this._useSelfClosingTagIfEmpty) {
|
||||
// Element empty tag end
|
||||
str += "/>";
|
||||
}
|
||||
else {
|
||||
// Element start and end tags
|
||||
str += ">" + childStr + "</" + this._name + ">";
|
||||
}
|
||||
}
|
||||
else if (this._useSelfClosingTagIfEmpty) {
|
||||
// Element empty tag end
|
||||
str += "/>";
|
||||
}
|
||||
else {
|
||||
// Element start and end tags
|
||||
str += "></" + this._name + ">";
|
||||
}
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* Returns true if the specified nodes are all character references,
|
||||
* entity references, or character data.
|
||||
*/
|
||||
XmlElement.prototype.allSameLineNodes = function (nodes) {
|
||||
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
||||
var node = nodes_1[_i];
|
||||
if (!((node instanceof XmlCharRef_1.default
|
||||
|| node instanceof XmlEntityRef_1.default
|
||||
|| node instanceof XmlCharData_1.default))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
/**
|
||||
* Returns true if the specified nodes are all character references,
|
||||
* entity references, or character data.
|
||||
*/
|
||||
XmlElement.prototype.onSameLine = function (prev, next) {
|
||||
return (prev instanceof XmlCharRef_1.default
|
||||
|| prev instanceof XmlEntityRef_1.default
|
||||
|| prev instanceof XmlCharData_1.default)
|
||||
&& (!(0, validate_1.isUndefined)(next)
|
||||
&& (next instanceof XmlCharRef_1.default
|
||||
|| next instanceof XmlEntityRef_1.default
|
||||
|| next instanceof XmlCharData_1.default));
|
||||
};
|
||||
return XmlElement;
|
||||
}());
|
||||
exports.default = XmlElement;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new entity reference.
|
||||
*/
|
||||
export interface IXmlEntityRefOptions {
|
||||
/**
|
||||
* The name of the entity to be referenced.
|
||||
*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Represents an entity reference.
|
||||
*
|
||||
* An entity reference is structured as follows, where `{name}` is the name of
|
||||
* the entity to be referenced:
|
||||
*
|
||||
* ```xml
|
||||
* &{entity};
|
||||
* ```
|
||||
*/
|
||||
export default class XmlEntityRef<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _name;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlEntityRefOptions);
|
||||
/**
|
||||
* Gets the name of this entity reference.
|
||||
*/
|
||||
get name(): string;
|
||||
/**
|
||||
* Sets the name of this entity reference.
|
||||
*/
|
||||
set name(name: string);
|
||||
/**
|
||||
* Returns an XML string representation of this entity reference.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this entity reference.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents an entity reference.
|
||||
*
|
||||
* An entity reference is structured as follows, where `{name}` is the name of
|
||||
* the entity to be referenced:
|
||||
*
|
||||
* ```xml
|
||||
* &{entity};
|
||||
* ```
|
||||
*/
|
||||
var XmlEntityRef = /** @class */ (function () {
|
||||
function XmlEntityRef(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.name = options.name;
|
||||
}
|
||||
Object.defineProperty(XmlEntityRef.prototype, "name", {
|
||||
/**
|
||||
* Gets the name of this entity reference.
|
||||
*/
|
||||
get: function () {
|
||||
return this._name;
|
||||
},
|
||||
/**
|
||||
* Sets the name of this entity reference.
|
||||
*/
|
||||
set: function (name) {
|
||||
if (this._validation && !(0, validate_1.validateName)(name)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": entity reference name"
|
||||
+ (" \"" + name + "\" should not contain characters not")
|
||||
+ " allowed in XML names");
|
||||
}
|
||||
this._name = name;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this entity reference.
|
||||
*/
|
||||
XmlEntityRef.prototype.toString = function () {
|
||||
return "&" + this._name + ";";
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this entity reference.
|
||||
*/
|
||||
XmlEntityRef.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlEntityRef;
|
||||
}());
|
||||
exports.default = XmlEntityRef;
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* The options used to create a new processing instruction.
|
||||
*/
|
||||
export interface IXmlProcInstOptions {
|
||||
/**
|
||||
* The target of the processing instruction.
|
||||
*/
|
||||
target: string;
|
||||
/**
|
||||
* The data of the processing instruction, or undefined if there is no
|
||||
* content.
|
||||
*/
|
||||
content?: string;
|
||||
}
|
||||
/**
|
||||
* Represents a processing instruction.
|
||||
*
|
||||
* A processing instruction is structured as follows, where `{target}` and
|
||||
* `{content}` are the target and content of the processing instruction
|
||||
* respectively:
|
||||
*
|
||||
* ```xml
|
||||
* <?{target} {content}?>
|
||||
* ```
|
||||
*/
|
||||
export default class XmlProcInst<Parent> {
|
||||
private readonly _validation;
|
||||
private readonly _parent;
|
||||
private _content;
|
||||
private _target;
|
||||
constructor(parent: Parent, validation: boolean, options: IXmlProcInstOptions);
|
||||
/**
|
||||
* Gets the content of this processing instruction.
|
||||
*/
|
||||
get content(): string | undefined;
|
||||
/**
|
||||
* Sets the content of this processing instruction.
|
||||
*/
|
||||
set content(content: string | undefined);
|
||||
/**
|
||||
* Gets the target of this processing instruction.
|
||||
*/
|
||||
get target(): string;
|
||||
/**
|
||||
* Sets the content of this processing instruction.
|
||||
*/
|
||||
set target(target: string);
|
||||
/**
|
||||
* Returns an XML string representation of this processing instruction.
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Returns the parent of this processing instruction.
|
||||
*/
|
||||
up(): Parent;
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var error_1 = require("../error");
|
||||
var validate_1 = require("../validate");
|
||||
/**
|
||||
* Represents a processing instruction.
|
||||
*
|
||||
* A processing instruction is structured as follows, where `{target}` and
|
||||
* `{content}` are the target and content of the processing instruction
|
||||
* respectively:
|
||||
*
|
||||
* ```xml
|
||||
* <?{target} {content}?>
|
||||
* ```
|
||||
*/
|
||||
var XmlProcInst = /** @class */ (function () {
|
||||
function XmlProcInst(parent, validation, options) {
|
||||
this._validation = validation;
|
||||
this._parent = parent;
|
||||
this.content = options.content;
|
||||
this.target = options.target;
|
||||
}
|
||||
Object.defineProperty(XmlProcInst.prototype, "content", {
|
||||
/**
|
||||
* Gets the content of this processing instruction.
|
||||
*/
|
||||
get: function () {
|
||||
return this._content;
|
||||
},
|
||||
/**
|
||||
* Sets the content of this processing instruction.
|
||||
*/
|
||||
set: function (content) {
|
||||
if (!(0, validate_1.isUndefined)(content)) {
|
||||
if (this._validation && !(0, validate_1.validateChar)(content)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": processing"
|
||||
+ (" instruction content \"" + content + "\" should")
|
||||
+ " not contain characters not allowed in XML");
|
||||
}
|
||||
else if (this._validation && content.indexOf("?>") !== -1) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": processing"
|
||||
+ (" instruction content \"" + content + "\" should")
|
||||
+ " not contain the string '?>'");
|
||||
}
|
||||
}
|
||||
this._content = content;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(XmlProcInst.prototype, "target", {
|
||||
/**
|
||||
* Gets the target of this processing instruction.
|
||||
*/
|
||||
get: function () {
|
||||
return this._target;
|
||||
},
|
||||
/**
|
||||
* Sets the content of this processing instruction.
|
||||
*/
|
||||
set: function (target) {
|
||||
if (this._validation && !(0, validate_1.validateName)(target)) {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": processing"
|
||||
+ (" instruction target \"" + target + "\" should")
|
||||
+ " not contain characters not allowed in XML"
|
||||
+ " names");
|
||||
}
|
||||
if (this._validation && target === "xml") {
|
||||
throw new Error((0, error_1.getContext)(this.up()) + ": processing"
|
||||
+ (" instruction target \"" + target + "\" should")
|
||||
+ " not be the string 'xml'");
|
||||
}
|
||||
this._target = target;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns an XML string representation of this processing instruction.
|
||||
*/
|
||||
XmlProcInst.prototype.toString = function () {
|
||||
if ((0, validate_1.isUndefined)(this._content)) {
|
||||
return "<?" + this._target + "?>";
|
||||
}
|
||||
else {
|
||||
return "<?" + this._target + " " + this._content + "?>";
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns the parent of this processing instruction.
|
||||
*/
|
||||
XmlProcInst.prototype.up = function () {
|
||||
return this._parent;
|
||||
};
|
||||
return XmlProcInst;
|
||||
}());
|
||||
exports.default = XmlProcInst;
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Formatting options for the string representation of an XML node.
|
||||
*/
|
||||
export interface IStringOptions {
|
||||
/**
|
||||
* Whether double quotes or single quotes should be used in XML attributes.
|
||||
* By default, single quotes are used.
|
||||
*/
|
||||
doubleQuotes?: boolean;
|
||||
/**
|
||||
* The indent string used for pretty-printing. The default indent string is
|
||||
* four spaces.
|
||||
*/
|
||||
indent?: string;
|
||||
/**
|
||||
* The newline string used for pretty-printing. The default newline string
|
||||
* is "\n".
|
||||
*/
|
||||
newline?: string;
|
||||
/**
|
||||
* Whether pretty-printing is enabled. By default, pretty-printing is
|
||||
* enabled.
|
||||
*/
|
||||
pretty?: boolean;
|
||||
}
|
||||
/**
|
||||
* Implementation of the IStringOptions interface used to provide default
|
||||
* values to fields.
|
||||
*/
|
||||
export declare class StringOptions implements IStringOptions {
|
||||
doubleQuotes: boolean;
|
||||
indent: string;
|
||||
newline: string;
|
||||
pretty: boolean;
|
||||
constructor(options: IStringOptions);
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StringOptions = void 0;
|
||||
var validate_1 = require("./validate");
|
||||
/**
|
||||
* Implementation of the IStringOptions interface used to provide default
|
||||
* values to fields.
|
||||
*/
|
||||
var StringOptions = /** @class */ (function () {
|
||||
function StringOptions(options) {
|
||||
this.doubleQuotes = false;
|
||||
this.indent = " ";
|
||||
this.newline = "\n";
|
||||
this.pretty = true;
|
||||
if (!(0, validate_1.isUndefined)(options.doubleQuotes)) {
|
||||
this.doubleQuotes = options.doubleQuotes;
|
||||
}
|
||||
if (!(0, validate_1.isUndefined)(options.indent)) {
|
||||
this.indent = options.indent;
|
||||
}
|
||||
if (!(0, validate_1.isUndefined)(options.newline)) {
|
||||
this.newline = options.newline;
|
||||
}
|
||||
if (!(0, validate_1.isUndefined)(options.pretty)) {
|
||||
this.pretty = options.pretty;
|
||||
}
|
||||
}
|
||||
return StringOptions;
|
||||
}());
|
||||
exports.StringOptions = StringOptions;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Returns true if the specified string only contains characters permitted by
|
||||
* the XML specification.
|
||||
*/
|
||||
export declare function validateChar(str: string): boolean;
|
||||
/**
|
||||
* Returns a version of the specified string that only contains characters
|
||||
* permitted by the XML specification, with invalid characters replaced
|
||||
* by the replacement character U+FFFD.
|
||||
*/
|
||||
export declare function fixChar(str: string): string;
|
||||
/**
|
||||
* Returns true if the specified string only contains a single character, and
|
||||
* that this character is permitted by the XML specification.
|
||||
*/
|
||||
export declare function validateSingleChar(str: string): boolean;
|
||||
/**
|
||||
* Returns true if the specified string only contains characters permitted by
|
||||
* the XML specification for names.
|
||||
*/
|
||||
export declare function validateName(str: string): boolean;
|
||||
/**
|
||||
* Returns a version of the specified string that only contains characters
|
||||
* permitted by the XML specification for names, with invalid characters
|
||||
* replaced by the replacement character U+FFFD.
|
||||
*/
|
||||
export declare function fixName(str: string): string;
|
||||
/**
|
||||
* Returns true if the specified value is undefined.
|
||||
*/
|
||||
export declare function isUndefined(val: unknown): val is undefined;
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright (C) 2016-2019 Michael Kourlas
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isUndefined = exports.fixName = exports.validateName = exports.validateSingleChar = exports.fixChar = exports.validateChar = void 0;
|
||||
/**
|
||||
* Returns true if the specified string only contains characters permitted by
|
||||
* the XML specification.
|
||||
*/
|
||||
function validateChar(str) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var firstChar = str.charCodeAt(i);
|
||||
if (firstChar === 0x9 || firstChar === 0xA || firstChar === 0xD
|
||||
|| (firstChar >= 0x20 && firstChar <= 0xD7FF)
|
||||
|| (firstChar >= 0xE000 && firstChar <= 0xFFFD)) {
|
||||
continue;
|
||||
}
|
||||
if (i + 1 === str.length) {
|
||||
return false;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var secondChar = str.charCodeAt(i + 1);
|
||||
if ((firstChar >= 0xD800 && firstChar <= 0xDBFF)
|
||||
&& (secondChar >= 0xDC00 && secondChar <= 0xDFFF)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.validateChar = validateChar;
|
||||
/**
|
||||
* Returns a version of the specified string that only contains characters
|
||||
* permitted by the XML specification, with invalid characters replaced
|
||||
* by the replacement character U+FFFD.
|
||||
*/
|
||||
function fixChar(str) {
|
||||
var newStr = "";
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var firstChar = str.charCodeAt(i);
|
||||
if (firstChar === 0x9 || firstChar === 0xA || firstChar === 0xD
|
||||
|| (firstChar >= 0x20 && firstChar <= 0xD7FF)
|
||||
|| (firstChar >= 0xE000 && firstChar <= 0xFFFD)) {
|
||||
newStr += str[i];
|
||||
continue;
|
||||
}
|
||||
if (i + 1 === str.length) {
|
||||
newStr += "\uFFFD";
|
||||
return newStr;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var secondChar = str.charCodeAt(i + 1);
|
||||
if ((firstChar >= 0xD800 && firstChar <= 0xDBFF)
|
||||
&& (secondChar >= 0xDC00 && secondChar <= 0xDFFF)) {
|
||||
newStr += str[i] + str[i + 1];
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
newStr += "\uFFFD";
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
exports.fixChar = fixChar;
|
||||
/**
|
||||
* Returns true if the specified string only contains a single character, and
|
||||
* that this character is permitted by the XML specification.
|
||||
*/
|
||||
function validateSingleChar(str) {
|
||||
if (str.length === 0) {
|
||||
return false;
|
||||
}
|
||||
var firstChar = str.charCodeAt(0);
|
||||
if (str.length === 1) {
|
||||
return (firstChar === 0x9 || firstChar === 0xA || firstChar === 0xD
|
||||
|| (firstChar >= 0x20 && firstChar <= 0xD7FF)
|
||||
|| (firstChar >= 0xE000 && firstChar <= 0xFFFD));
|
||||
}
|
||||
if (str.length !== 2) {
|
||||
return false;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var secondChar = str.charCodeAt(1);
|
||||
return ((firstChar >= 0xD800 && firstChar <= 0xDBFF)
|
||||
&& (secondChar >= 0xDC00 && secondChar <= 0xDFFF));
|
||||
}
|
||||
exports.validateSingleChar = validateSingleChar;
|
||||
/**
|
||||
* Returns true if the specified string only contains characters permitted by
|
||||
* the XML specification for names.
|
||||
*/
|
||||
function validateName(str) {
|
||||
if (str.length === 0) {
|
||||
return false;
|
||||
}
|
||||
var initialFirstChar = str.charCodeAt(0);
|
||||
var initialFirstCharMatch = (initialFirstChar === 0x3A
|
||||
|| initialFirstChar === 0x5F
|
||||
|| (initialFirstChar >= 0x41 && initialFirstChar <= 0x5A)
|
||||
|| (initialFirstChar >= 0x61 && initialFirstChar <= 0x7A)
|
||||
|| (initialFirstChar >= 0xC0 && initialFirstChar <= 0xD6)
|
||||
|| (initialFirstChar >= 0xD8 && initialFirstChar <= 0xF6)
|
||||
|| (initialFirstChar >= 0XF8 && initialFirstChar <= 0X2FF)
|
||||
|| (initialFirstChar >= 0x370 && initialFirstChar <= 0x37D)
|
||||
|| (initialFirstChar >= 0x37F && initialFirstChar <= 0X1FFF)
|
||||
|| (initialFirstChar >= 0x200C && initialFirstChar <= 0x200D)
|
||||
|| (initialFirstChar >= 0x2070 && initialFirstChar <= 0x218F)
|
||||
|| (initialFirstChar >= 0x2C00 && initialFirstChar <= 0x2FEF)
|
||||
|| (initialFirstChar >= 0x3001 && initialFirstChar <= 0xD7FF)
|
||||
|| (initialFirstChar >= 0xF900 && initialFirstChar <= 0xFDCF)
|
||||
|| (initialFirstChar >= 0xFDF0 && initialFirstChar <= 0xFFFD));
|
||||
if (str.length === 1) {
|
||||
return initialFirstCharMatch;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var initialSecondChar = str.charCodeAt(1);
|
||||
var initialSecondCharMatch = ((initialFirstChar >= 0xD800 && initialFirstChar <= 0xDB7F)
|
||||
&& (initialSecondChar >= 0xDC00 && initialSecondChar <= 0xDFFF));
|
||||
if (!initialFirstCharMatch && !initialSecondCharMatch) {
|
||||
return false;
|
||||
}
|
||||
var start = initialSecondCharMatch ? 2 : 1;
|
||||
for (var i = start; i < str.length; i++) {
|
||||
var firstChar = str.charCodeAt(i);
|
||||
if (firstChar === 0x3A
|
||||
|| firstChar === 0x5F
|
||||
|| firstChar === 0x2D
|
||||
|| firstChar === 0x2E
|
||||
|| firstChar === 0xB7
|
||||
|| (firstChar >= 0x30 && firstChar <= 0x39)
|
||||
|| (firstChar >= 0x41 && firstChar <= 0x5A)
|
||||
|| (firstChar >= 0x61 && firstChar <= 0x7A)
|
||||
|| (firstChar >= 0xC0 && firstChar <= 0xD6)
|
||||
|| (firstChar >= 0xD8 && firstChar <= 0xF6)
|
||||
|| (firstChar >= 0XF8 && firstChar <= 0X2FF)
|
||||
|| (firstChar >= 0x300 && firstChar <= 0x36F)
|
||||
|| (firstChar >= 0x370 && firstChar <= 0x37D)
|
||||
|| (firstChar >= 0x37F && firstChar <= 0X1FFF)
|
||||
|| (firstChar >= 0x200C && firstChar <= 0x200D)
|
||||
|| (firstChar >= 0x203F && firstChar <= 0x2040)
|
||||
|| (firstChar >= 0x2070 && firstChar <= 0x218F)
|
||||
|| (firstChar >= 0x2C00 && firstChar <= 0x2FEF)
|
||||
|| (firstChar >= 0x3001 && firstChar <= 0xD7FF)
|
||||
|| (firstChar >= 0xF900 && firstChar <= 0xFDCF)
|
||||
|| (firstChar >= 0xFDF0 && firstChar <= 0xFFFD)) {
|
||||
continue;
|
||||
}
|
||||
if (i + 1 === str.length) {
|
||||
return false;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var secondChar = str.charCodeAt(i + 1);
|
||||
if ((firstChar >= 0xD800 && firstChar <= 0xDB7F)
|
||||
&& (secondChar >= 0xDC00 && secondChar <= 0xDFFF)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.validateName = validateName;
|
||||
/**
|
||||
* Returns a version of the specified string that only contains characters
|
||||
* permitted by the XML specification for names, with invalid characters
|
||||
* replaced by the replacement character U+FFFD.
|
||||
*/
|
||||
function fixName(str) {
|
||||
var newStr = "";
|
||||
if (str.length === 0) {
|
||||
return newStr;
|
||||
}
|
||||
var initialFirstChar = str.charCodeAt(0);
|
||||
var initialFirstCharMatch = (initialFirstChar === 0x3A
|
||||
|| initialFirstChar === 0x5F
|
||||
|| (initialFirstChar >= 0x41 && initialFirstChar <= 0x5A)
|
||||
|| (initialFirstChar >= 0x61 && initialFirstChar <= 0x7A)
|
||||
|| (initialFirstChar >= 0xC0 && initialFirstChar <= 0xD6)
|
||||
|| (initialFirstChar >= 0xD8 && initialFirstChar <= 0xF6)
|
||||
|| (initialFirstChar >= 0XF8 && initialFirstChar <= 0X2FF)
|
||||
|| (initialFirstChar >= 0x370 && initialFirstChar <= 0x37D)
|
||||
|| (initialFirstChar >= 0x37F && initialFirstChar <= 0X1FFF)
|
||||
|| (initialFirstChar >= 0x200C && initialFirstChar <= 0x200D)
|
||||
|| (initialFirstChar >= 0x2070 && initialFirstChar <= 0x218F)
|
||||
|| (initialFirstChar >= 0x2C00 && initialFirstChar <= 0x2FEF)
|
||||
|| (initialFirstChar >= 0x3001 && initialFirstChar <= 0xD7FF)
|
||||
|| (initialFirstChar >= 0xF900 && initialFirstChar <= 0xFDCF)
|
||||
|| (initialFirstChar >= 0xFDF0 && initialFirstChar <= 0xFFFD));
|
||||
if (str.length === 1) {
|
||||
if (initialFirstCharMatch) {
|
||||
newStr = str[0];
|
||||
}
|
||||
else {
|
||||
newStr = "\uFFFD";
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var initialSecondChar = str.charCodeAt(1);
|
||||
var initialSecondCharMatch = ((initialFirstChar >= 0xD800 && initialFirstChar <= 0xDB7F)
|
||||
&& (initialSecondChar >= 0xDC00 && initialSecondChar <= 0xDFFF));
|
||||
if (initialSecondCharMatch) {
|
||||
newStr = str[0] + str[1];
|
||||
}
|
||||
else if (initialFirstCharMatch) {
|
||||
newStr = str[0];
|
||||
}
|
||||
else {
|
||||
newStr = "\uFFFD";
|
||||
}
|
||||
var start = initialSecondCharMatch ? 2 : 1;
|
||||
for (var i = start; i < str.length; i++) {
|
||||
var firstChar = str.charCodeAt(i);
|
||||
if (firstChar === 0x3A
|
||||
|| firstChar === 0x5F
|
||||
|| firstChar === 0x2D
|
||||
|| firstChar === 0x2E
|
||||
|| firstChar === 0xB7
|
||||
|| (firstChar >= 0x30 && firstChar <= 0x39)
|
||||
|| (firstChar >= 0x41 && firstChar <= 0x5A)
|
||||
|| (firstChar >= 0x61 && firstChar <= 0x7A)
|
||||
|| (firstChar >= 0xC0 && firstChar <= 0xD6)
|
||||
|| (firstChar >= 0xD8 && firstChar <= 0xF6)
|
||||
|| (firstChar >= 0XF8 && firstChar <= 0X2FF)
|
||||
|| (firstChar >= 0x300 && firstChar <= 0x36F)
|
||||
|| (firstChar >= 0x370 && firstChar <= 0x37D)
|
||||
|| (firstChar >= 0x37F && firstChar <= 0X1FFF)
|
||||
|| (firstChar >= 0x200C && firstChar <= 0x200D)
|
||||
|| (firstChar >= 0x203F && firstChar <= 0x2040)
|
||||
|| (firstChar >= 0x2070 && firstChar <= 0x218F)
|
||||
|| (firstChar >= 0x2C00 && firstChar <= 0x2FEF)
|
||||
|| (firstChar >= 0x3001 && firstChar <= 0xD7FF)
|
||||
|| (firstChar >= 0xF900 && firstChar <= 0xFDCF)
|
||||
|| (firstChar >= 0xFDF0 && firstChar <= 0xFFFD)) {
|
||||
newStr += str[i];
|
||||
continue;
|
||||
}
|
||||
if (i + 1 === str.length) {
|
||||
newStr += "\uFFFD";
|
||||
return newStr;
|
||||
}
|
||||
// UTF-16 surrogate characters
|
||||
var secondChar = str.charCodeAt(i + 1);
|
||||
if ((firstChar >= 0xD800 && firstChar <= 0xDB7F)
|
||||
&& (secondChar >= 0xDC00 && secondChar <= 0xDFFF)) {
|
||||
newStr += str[i] + str[i + 1];
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
newStr += "\uFFFD";
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
exports.fixName = fixName;
|
||||
/**
|
||||
* Returns true if the specified value is undefined.
|
||||
*/
|
||||
function isUndefined(val) {
|
||||
return Object.prototype.toString.call(val) === "[object Undefined]";
|
||||
}
|
||||
exports.isUndefined = isUndefined;
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "xmlcreate",
|
||||
"version": "2.0.4",
|
||||
"description": "Simple XML builder for Node.js",
|
||||
"keywords": [
|
||||
"build",
|
||||
"builder",
|
||||
"create",
|
||||
"creator",
|
||||
"xml"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"author": {
|
||||
"name": "Michael Kourlas",
|
||||
"email": "michael@kourlas.com"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"CHANGES.md",
|
||||
"LICENSE",
|
||||
"NOTICE",
|
||||
"package.json",
|
||||
"README.md"
|
||||
],
|
||||
"main": "./lib/main.js",
|
||||
"typings": "./lib/main",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/michaelkourlas/node-xmlcreate.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run-script prod && npm run-script test-prod && npm run-script docs",
|
||||
"clean": "rimraf lib",
|
||||
"clean-docs": "rimraf docs",
|
||||
"clean-test": "rimraf test/lib",
|
||||
"dev": "npm run-script clean && npm run-script lint && tsc -p tsconfig.json --sourceMap",
|
||||
"docs": "npm run-script clean-docs && typedoc --out docs --excludePrivate src/main.ts",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"prod": "npm run-script clean && npm run-script lint && tsc -p tsconfig.json",
|
||||
"test-dev": "npm run-script clean-test && tsc -p test/tsconfig.json --sourceMap && mocha --recursive test/lib",
|
||||
"test-prod": "npm run-script clean-test && tsc -p test/tsconfig.json && mocha --recursive test/lib"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.22",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.2.0",
|
||||
"@typescript-eslint/parser": "^5.2.0",
|
||||
"chai": "^4.3.4",
|
||||
"eslint": "^8.1.0",
|
||||
"mocha": "^9.1.3",
|
||||
"rimraf": "^3.0.2",
|
||||
"typedoc": "^0.22.7",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user