Skip to content

Commit 01b5a54

Browse files
committed
Restored DTD validation
1 parent a81d9e7 commit 01b5a54

33 files changed

Lines changed: 3458 additions & 425 deletions

.gitignore

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
.DS_Store
2-
package-lock.json
3-
/node_modules/
4-
/dist/
5-
/.vscode/
6-
/.scannerwork/
2+
node_modules/
3+
dist/
4+
.vscode/
5+
.scannerwork/
76
ts/test.ts
8-
test.xml
9-
catalog/
10-
tests/
7+
test.xml

package-lock.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "typesxml",
33
"productName": "TypesXML",
4-
"version": "1.9.0",
4+
"version": "1.12.0",
55
"description": "Open source XML library written in TypeScript",
66
"keywords": [
77
"XML",
88
"Parser",
99
"DOM",
1010
"SAX",
11-
"DTD"
11+
"DTD",
12+
"Default attributes",
13+
"TypeScript"
1214
],
1315
"scripts": {
1416
"build": "tsc"

ts/Catalog.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,22 @@ export class Catalog {
317317
}
318318
return undefined;
319319
}
320+
321+
matchURI(uri: string): string | undefined {
322+
if (uri) {
323+
// Apply URI rewrites first
324+
for (let pair of this.uriRewrites) {
325+
if (uri.startsWith(pair[0])) {
326+
uri = pair[1] + uri.substring(pair[0].length);
327+
}
328+
}
329+
// Look up in URI catalog
330+
if (this.uriCatalog.has(uri)) {
331+
return this.uriCatalog.get(uri);
332+
}
333+
}
334+
return undefined;
335+
}
320336
}
321337

322338

ts/Constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ export class Constants {
3030
static readonly ELEMENT_DECL_NODE: number = 12;
3131
static readonly INTERNAL_SUBSET_NODE: number = 13;
3232
static readonly NOTATION_DECL_NODE: number = 14;
33+
34+
// RelaxNG Namespace URI
35+
static readonly RELAXNG_NS_URI: string = 'http://relaxng.org/ns/structure/1.0';
3336
}

ts/ContentHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*******************************************************************************/
1212

1313
import { Catalog } from "./Catalog";
14+
import { Grammar } from "./grammar/Grammar";
1415
import { XMLAttribute } from "./XMLAttribute";
1516

1617
export interface ContentHandler {
@@ -40,4 +41,6 @@ export interface ContentHandler {
4041
endDTD(): void;
4142

4243
skippedEntity(name: string): void;
44+
45+
getGrammar(): Grammar | undefined;
4346
}

ts/DOMBuilder.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class DOMBuilder implements ContentHandler {
2121
stack: Array<XMLElement> = [];
2222
catalog: Catalog | undefined;
2323
dtdParser: DTDParser | undefined;
24-
grammarUrl: string | undefined;
2524
grammar: Grammar | undefined;
2625

2726
initialize(): void {
@@ -34,10 +33,6 @@ export class DOMBuilder implements ContentHandler {
3433
this.catalog = catalog;
3534
}
3635

37-
setDTDParser(dtdParser: DTDParser): void {
38-
this.dtdParser = dtdParser;
39-
}
40-
4136
getDocument(): XMLDocument | undefined {
4237
return this.document;
4338
}
@@ -117,14 +112,6 @@ export class DOMBuilder implements ContentHandler {
117112
} else {
118113
this.document?.addProcessingInstruction(pi);
119114
}
120-
if (target === 'xml-model' && this.catalog) {
121-
// TODO process the xml-model
122-
/*
123-
let atts: Map<string, string> = this.parseXmlModel(data);
124-
let href: string = atts.get('href');
125-
let schematypens: string = atts.get('schematypens');
126-
*/
127-
}
128115
}
129116

130117
parseXmlModel(text: string): Map<string, string> {
@@ -187,13 +174,12 @@ export class DOMBuilder implements ContentHandler {
187174
if (this.catalog) {
188175
let url = this.catalog.resolveEntity(publicId, systemId);
189176
if (url) {
190-
this.grammarUrl = url;
191-
// TODO check grammar type (DTD, XSD or RelaxNG) and use the ritght parser
192-
if (this.dtdParser && this.grammarUrl) {
193-
let dtdGrammar: Grammar = this.dtdParser.parseDTD(this.grammarUrl);
194-
if (dtdGrammar) {
195-
this.grammar = dtdGrammar;
196-
}
177+
if (!this.dtdParser) {
178+
this.dtdParser = new DTDParser();
179+
}
180+
let dtdGrammar: Grammar = this.dtdParser.parseDTD(url);
181+
if (dtdGrammar) {
182+
this.grammar = dtdGrammar;
197183
}
198184
}
199185
}
@@ -203,6 +189,10 @@ export class DOMBuilder implements ContentHandler {
203189
// do nothing
204190
}
205191

192+
getGrammar(): Grammar | undefined {
193+
return this.grammar;
194+
}
195+
206196
skippedEntity(name: string): void {
207197
// TODO
208198
throw new Error("Method not implemented.");

0 commit comments

Comments
 (0)