@xmldom/xmldom 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/lib/dom-parser.js +19 -8
- package/lib/dom.js +7 -1
- package/lib/index.js +4 -0
- package/package.json +7 -10
- package/readme.md +82 -73
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 0.7.3
|
|
8
|
+
|
|
9
|
+
[Commits](https://github.com/xmldom/xmldom/compare/0.7.2...0.7.3)
|
|
10
|
+
|
|
11
|
+
### Fixes:
|
|
12
|
+
|
|
13
|
+
- Add doctype when parsing from string [`#277`](https://github.com/xmldom/xmldom/issues/277) / [`#301`](https://github.com/xmldom/xmldom/pull/301)
|
|
14
|
+
- Correct typo in error message [`#294`](https://github.com/xmldom/xmldom/pull/294)
|
|
15
|
+
Thank you [@rrthomas](https://github.com/rrthomas)
|
|
16
|
+
|
|
17
|
+
### Refactor:
|
|
18
|
+
|
|
19
|
+
- Improve exports & require statements, new main package entry [`#233`](https://github.com/xmldom/xmldom/pull/233)
|
|
20
|
+
|
|
21
|
+
### Docs:
|
|
22
|
+
|
|
23
|
+
- Fix Stryker badge [`#298`](https://github.com/xmldom/xmldom/pull/298)
|
|
24
|
+
- Fix link to help-wanted issues [`#299`](https://github.com/xmldom/xmldom/pull/299)
|
|
25
|
+
|
|
26
|
+
### Chore:
|
|
27
|
+
|
|
28
|
+
- Execute stryker:dry-run on branches [`#302`](https://github.com/xmldom/xmldom/pull/302)
|
|
29
|
+
- Fix stryker config [`#300`](https://github.com/xmldom/xmldom/pull/300)
|
|
30
|
+
- Split test and lint scripts [`#297`](https://github.com/xmldom/xmldom/pull/297)
|
|
31
|
+
- Switch to stryker dashboard owned by org [`#292`](https://github.com/xmldom/xmldom/pull/292)
|
|
32
|
+
|
|
7
33
|
## 0.7.2
|
|
8
34
|
|
|
9
35
|
[Commits](https://github.com/xmldom/xmldom/compare/0.7.1...0.7.2)
|
package/lib/dom-parser.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
var conventions = require("./conventions");
|
|
2
|
+
var dom = require('./dom')
|
|
2
3
|
var entities = require('./entities');
|
|
4
|
+
var sax = require('./sax');
|
|
5
|
+
|
|
6
|
+
var DOMImplementation = dom.DOMImplementation;
|
|
3
7
|
|
|
4
8
|
var NAMESPACE = conventions.NAMESPACE;
|
|
5
9
|
|
|
10
|
+
var ParseError = sax.ParseError;
|
|
11
|
+
var XMLReader = sax.XMLReader;
|
|
12
|
+
|
|
6
13
|
function DOMParser(options){
|
|
7
14
|
this.options = options ||{locator:{}};
|
|
8
15
|
}
|
|
@@ -170,6 +177,7 @@ DOMHandler.prototype = {
|
|
|
170
177
|
var dt = impl.createDocumentType(name, publicId, systemId);
|
|
171
178
|
this.locator && position(this.locator,dt)
|
|
172
179
|
appendElement(this, dt);
|
|
180
|
+
this.doc.doctype = dt;
|
|
173
181
|
}
|
|
174
182
|
},
|
|
175
183
|
/**
|
|
@@ -246,12 +254,15 @@ function appendElement (hander,node) {
|
|
|
246
254
|
}
|
|
247
255
|
}//appendChild and setAttributeNS are preformance key
|
|
248
256
|
|
|
249
|
-
//if(typeof require == 'function'){
|
|
250
|
-
var sax = require('./sax');
|
|
251
|
-
var XMLReader = sax.XMLReader;
|
|
252
|
-
var ParseError = sax.ParseError;
|
|
253
|
-
var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
|
|
254
|
-
exports.XMLSerializer = require('./dom').XMLSerializer ;
|
|
255
|
-
exports.DOMParser = DOMParser;
|
|
256
257
|
exports.__DOMHandler = DOMHandler;
|
|
257
|
-
|
|
258
|
+
exports.DOMParser = DOMParser;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @deprecated Import/require from main entry point instead
|
|
262
|
+
*/
|
|
263
|
+
exports.DOMImplementation = dom.DOMImplementation;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @deprecated Import/require from main entry point instead
|
|
267
|
+
*/
|
|
268
|
+
exports.XMLSerializer = dom.XMLSerializer;
|
package/lib/dom.js
CHANGED
|
@@ -81,7 +81,7 @@ function _extends(Class,Super){
|
|
|
81
81
|
}
|
|
82
82
|
if(pt.constructor != Class){
|
|
83
83
|
if(typeof Class != 'function'){
|
|
84
|
-
console.error("
|
|
84
|
+
console.error("unknown Class:"+Class)
|
|
85
85
|
}
|
|
86
86
|
pt.constructor = Class
|
|
87
87
|
}
|
|
@@ -689,6 +689,12 @@ Document.prototype = {
|
|
|
689
689
|
//implementation : null,
|
|
690
690
|
nodeName : '#document',
|
|
691
691
|
nodeType : DOCUMENT_NODE,
|
|
692
|
+
/**
|
|
693
|
+
* The DocumentType node of the document.
|
|
694
|
+
*
|
|
695
|
+
* @readonly
|
|
696
|
+
* @type DocumentType
|
|
697
|
+
*/
|
|
692
698
|
doctype : null,
|
|
693
699
|
documentElement : null,
|
|
694
700
|
_inc : 1,
|
package/lib/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmldom/xmldom",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"w3c",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git://github.com/xmldom/xmldom.git"
|
|
19
19
|
},
|
|
20
|
-
"main": "lib/
|
|
20
|
+
"main": "lib/index.js",
|
|
21
21
|
"types": "index.d.ts",
|
|
22
22
|
"files": [
|
|
23
23
|
"CHANGELOG.md",
|
|
@@ -27,13 +27,11 @@
|
|
|
27
27
|
"lib"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"lint": "
|
|
31
|
-
"
|
|
32
|
-
"start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test'",
|
|
30
|
+
"lint": "eslint lib test",
|
|
31
|
+
"start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
|
|
33
32
|
"stryker": "stryker run",
|
|
34
|
-
"
|
|
35
|
-
"test
|
|
36
|
-
"test:jest": "jest"
|
|
33
|
+
"stryker:dry-run": "stryker run -m '' --reporters progress",
|
|
34
|
+
"test": "jest"
|
|
37
35
|
},
|
|
38
36
|
"engines": {
|
|
39
37
|
"node": ">=10.0.0"
|
|
@@ -44,11 +42,10 @@
|
|
|
44
42
|
"eslint": "^7.32.0",
|
|
45
43
|
"eslint-config-prettier": "^8.3.0",
|
|
46
44
|
"eslint-plugin-es5": "^1.5.0",
|
|
47
|
-
"eslint-plugin-prettier": "^3.4.
|
|
45
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
48
46
|
"get-stream": "^6.0.1",
|
|
49
47
|
"jest": "^27.0.6",
|
|
50
48
|
"nodemon": "^2.0.12",
|
|
51
|
-
"npm-run-all": "^4.1.5",
|
|
52
49
|
"prettier": "^2.3.2",
|
|
53
50
|
"xmltest": "^1.5.0",
|
|
54
51
|
"yauzl": "^2.10.0"
|
package/readme.md
CHANGED
|
@@ -1,85 +1,36 @@
|
|
|
1
1
|
# @xmldom/xmldom
|
|
2
2
|
|
|
3
|
+
***Since version 0.7.0 this package is published to npm as [`@xmldom/xmldom`](https://www.npmjs.com/package/@xmldom/xmldom) and no longer as [`xmldom`](https://www.npmjs.com/package/xmldom), because [we are no longer able to publish `xmldom`](https://github.com/xmldom/xmldom/issues/271).***
|
|
4
|
+
*For better readability in the docs we will continue to talk about this library as "xmldom".*
|
|
5
|
+
|
|
3
6
|
[](LICENSE)
|
|
4
7
|
[](https://www.npmjs.com/package/@xmldom/xmldom)
|
|
5
8
|
[](https://github.com/xmldom/xmldom/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
|
6
|
-
[.**
|
|
10
|
-
|
|
11
|
-
*For better readability in the docs we will continue to talk about this library as "xmldom".*
|
|
12
|
-
|
|
13
|
-
xmldom is a javascript [ponyfill](https://ponyfill.com/) for the following APIs supported in browsers:
|
|
14
|
-
- convert an XML string into a DOM tree (`new DOMParser().parseFromString(xml, mimeType)` => `Document`)
|
|
15
|
-
- create, access and modify a DOM tree (`new DOMImplementation().createDocument(...)` => `Document`, )
|
|
16
|
-
- serialize a DOM tree back into an XML string (`new XMLSerializer().serializeToString(node)` => `string`)
|
|
17
|
-
|
|
18
|
-
Note that this `xmldom` library is not required if your code targets a modern browser. But this library is recommended if your code needs to also work in other runtimes like NodeJS or Rhino.
|
|
19
|
-
|
|
20
|
-
## Specs
|
|
9
|
+
[](https://github.com/xmldom/xmldom/issues?q=is%3Aissue+is%3Aopen+label%3Ahelp-wanted)
|
|
10
|
+
[](https://dashboard.stryker-mutator.io/reports/github.com/xmldom/xmldom/master)
|
|
21
11
|
|
|
22
|
-
The implementation is based on several specifications:
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
xmldom is a javascript [ponyfill](https://ponyfill.com/) to provide the following APIs [that are present in modern browsers](https://caniuse.com/xml-serializer) to other runtimes:
|
|
14
|
+
- convert an XML string into a DOM tree
|
|
15
|
+
```
|
|
16
|
+
new DOMParser().parseFromString(xml, mimeType) => Document
|
|
17
|
+
```
|
|
18
|
+
- create, access and modify a DOM tree
|
|
19
|
+
```
|
|
20
|
+
new DOMImplementation().createDocument(...) => Document
|
|
21
|
+
```
|
|
22
|
+
- serialize a DOM tree back into an XML string
|
|
23
|
+
```
|
|
24
|
+
new XMLSerializer().serializeToString(node) => string
|
|
25
|
+
```
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
The target runtimes `xmldom` supports are currently Node >= v10 (ES5) and Rhino ([not tested as part of CI](https://github.com/xmldom/xmldom/discussions/214)).
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Note that there are some known deviations between this implementation and the W3 specifications.
|
|
34
|
-
|
|
35
|
-
Note: [The latest version of this spec](https://w3c.github.io/DOM-Parsing/) has the status "Editors Draft", since it is under active development. One major change is that [the definition of the `DOMParser` interface has been moved to the HTML spec](https://w3c.github.io/DOM-Parsing/#the-domparser-interface)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### DOM
|
|
39
|
-
|
|
40
|
-
The original author claims that xmldom implements [DOM Level 2] in a "fully compatible" way and some parts of [DOM Level 3], but there are not enough tests to prove this. Both Specifications are now superseded by the [DOM Level 4 aka Living standard] wich has a much broader scope than xmldom.
|
|
41
|
-
|
|
42
|
-
xmldom implements the following interfaces (most constructors are currently not exposed):
|
|
43
|
-
- `Attr`
|
|
44
|
-
- `CDATASection`
|
|
45
|
-
- `CharacterData`
|
|
46
|
-
- `Comment`
|
|
47
|
-
- `Document`
|
|
48
|
-
- `DocumentFragment`
|
|
49
|
-
- `DocumentType`
|
|
50
|
-
- `DOMException` (constructor exposed)
|
|
51
|
-
- `DOMImplementation` (constructor exposed)
|
|
52
|
-
- `Element`
|
|
53
|
-
- `Entity`
|
|
54
|
-
- `EntityReference`
|
|
55
|
-
- `LiveNodeList`
|
|
56
|
-
- `NamedNodeMap`
|
|
57
|
-
- `Node` (constructor exposed)
|
|
58
|
-
- `NodeList`
|
|
59
|
-
- `Notation`
|
|
60
|
-
- `ProcessingInstruction`
|
|
61
|
-
- `Text`
|
|
62
|
-
|
|
63
|
-
more details are available in the (incomplete) [API Reference](#api-reference) section.
|
|
64
|
-
|
|
65
|
-
### HTML
|
|
66
|
-
|
|
67
|
-
xmldom does not have any goal of supporting the full spec, but it has some capability to parse, report and serialize things differently when "detecting HTML" (by checking the default namespace).
|
|
68
|
-
There is an upcoming change to better align the implementation with the latest specs, related to <https://github.com/xmldom/xmldom/issues/203>.
|
|
69
|
-
|
|
70
|
-
### SAX, XML, XMLNS
|
|
71
|
-
|
|
72
|
-
xmldom has an own SAX parser implementation to do the actual parsing, which implements some interfaces in alignment with the Java interfaces SAX defines:
|
|
73
|
-
- `XMLReader`
|
|
74
|
-
- `DOMHandler`
|
|
75
|
-
|
|
76
|
-
There is an idea/proposal to make ti possible to replace it with something else in <https://github.com/xmldom/xmldom/issues/55>
|
|
29
|
+
When deciding how to fix bugs or implement features, `xmldom` tries to stay as close as possible to the various [related specifications/standards](#specs).
|
|
30
|
+
As indicated by the version starting with `0.`, this implementation is not feature complete and some implemented features differ from what the specifications describe.
|
|
31
|
+
**Issues and PRs for such differences are always welcome, even when they only provide a failing test case.**
|
|
77
32
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
**Original project location:** <https://github.com/jindw/xmldom>
|
|
81
|
-
|
|
82
|
-
More details about the transition can be found in the [CHANGELOG](CHANGELOG.md#maintainer-changes) and in <https://github.com/xmldom/xmldom/issues/62>
|
|
33
|
+
This project was forked from it's [original source](https://github.com/jindw/xmldom) in 2019, more details about that transition can be found in the [CHANGELOG](CHANGELOG.md#maintainer-changes).
|
|
83
34
|
|
|
84
35
|
## Usage
|
|
85
36
|
|
|
@@ -121,7 +72,7 @@ import { DOMParser } from '@xmldom/xmldom'
|
|
|
121
72
|
```javascript
|
|
122
73
|
parseFromString(xmlsource,mimeType)
|
|
123
74
|
```
|
|
124
|
-
* **options extension** _by xmldom_(not
|
|
75
|
+
* **options extension** _by xmldom_ (not DOM standard!!)
|
|
125
76
|
|
|
126
77
|
```javascript
|
|
127
78
|
//added the options argument
|
|
@@ -327,3 +278,61 @@ import { DOMParser } from '@xmldom/xmldom'
|
|
|
327
278
|
lineNumber
|
|
328
279
|
//Numbered starting from '1'
|
|
329
280
|
columnNumber
|
|
281
|
+
|
|
282
|
+
## Specs
|
|
283
|
+
|
|
284
|
+
The implementation is based on several specifications:
|
|
285
|
+
|
|
286
|
+
<!-- Should open in new tab and the links in the SVG should be clickable there! -->
|
|
287
|
+
<a href="https://raw.githubusercontent.com/xmldom/xmldom/master/docs/specs.svg" target="_blank" rel="noopener noreferrer nofollow" ></a>
|
|
288
|
+
|
|
289
|
+
### DOM Parsing and Serialization
|
|
290
|
+
|
|
291
|
+
From the [W3C DOM Parsing and Serialization (WD 2016)](https://www.w3.org/TR/2016/WD-DOM-Parsing-20160517/) `xmldom` provides an implementation for the interfaces:
|
|
292
|
+
- `DOMParser`
|
|
293
|
+
- `XMLSerializer`
|
|
294
|
+
|
|
295
|
+
Note that there are some known deviations between this implementation and the W3 specifications.
|
|
296
|
+
|
|
297
|
+
Note: [The latest version of this spec](https://w3c.github.io/DOM-Parsing/) has the status "Editors Draft", since it is under active development. One major change is that [the definition of the `DOMParser` interface has been moved to the HTML spec](https://w3c.github.io/DOM-Parsing/#the-domparser-interface)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
### DOM
|
|
301
|
+
|
|
302
|
+
The original author claims that xmldom implements [DOM Level 2] in a "fully compatible" way and some parts of [DOM Level 3], but there are not enough tests to prove this. Both Specifications are now superseded by the [DOM Level 4 aka Living standard] wich has a much broader scope than xmldom.
|
|
303
|
+
|
|
304
|
+
xmldom implements the following interfaces (most constructors are currently not exposed):
|
|
305
|
+
- `Attr`
|
|
306
|
+
- `CDATASection`
|
|
307
|
+
- `CharacterData`
|
|
308
|
+
- `Comment`
|
|
309
|
+
- `Document`
|
|
310
|
+
- `DocumentFragment`
|
|
311
|
+
- `DocumentType`
|
|
312
|
+
- `DOMException` (constructor exposed)
|
|
313
|
+
- `DOMImplementation` (constructor exposed)
|
|
314
|
+
- `Element`
|
|
315
|
+
- `Entity`
|
|
316
|
+
- `EntityReference`
|
|
317
|
+
- `LiveNodeList`
|
|
318
|
+
- `NamedNodeMap`
|
|
319
|
+
- `Node` (constructor exposed)
|
|
320
|
+
- `NodeList`
|
|
321
|
+
- `Notation`
|
|
322
|
+
- `ProcessingInstruction`
|
|
323
|
+
- `Text`
|
|
324
|
+
|
|
325
|
+
more details are available in the (incomplete) [API Reference](#api-reference) section.
|
|
326
|
+
|
|
327
|
+
### HTML
|
|
328
|
+
|
|
329
|
+
xmldom does not have any goal of supporting the full spec, but it has some capability to parse, report and serialize things differently when "detecting HTML" (by checking the default namespace).
|
|
330
|
+
There is an upcoming change to better align the implementation with the latest specs, related to <https://github.com/xmldom/xmldom/issues/203>.
|
|
331
|
+
|
|
332
|
+
### SAX, XML, XMLNS
|
|
333
|
+
|
|
334
|
+
xmldom has an own SAX parser implementation to do the actual parsing, which implements some interfaces in alignment with the Java interfaces SAX defines:
|
|
335
|
+
- `XMLReader`
|
|
336
|
+
- `DOMHandler`
|
|
337
|
+
|
|
338
|
+
There is an idea/proposal to make ti possible to replace it with something else in <https://github.com/xmldom/xmldom/issues/55>
|