Skip to content

Commit efb191a

Browse files
Merge pull request #9 from jacksierkstra/develop
Changed default xsd parser to be the pipeline and fixed a bug for the…
2 parents bfa01b5 + f915f37 commit efb191a

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/core/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ValidationResult } from "@lib/types/validation";
22
import { Validator, ValidatorImpl } from "@lib/validator/validator";
33
import { XMLParser, XMLParserImpl } from "@lib/xml/parser";
44
import { XSDParser } from "@lib/xsd/parser";
5-
import { XSDStandardParserImpl } from "@lib/xsd/standard";
5+
import { XSDPipelineParserImpl } from "@lib/xsd/pipeline/parser";
66

77
export class Checkr {
88

@@ -12,7 +12,7 @@ export class Checkr {
1212

1313
constructor() {
1414
this.xmlParser = new XMLParserImpl();
15-
this.xsdParser = new XSDStandardParserImpl(this.xmlParser);
15+
this.xsdParser = new XSDPipelineParserImpl(this.xmlParser);
1616
this.validator = new ValidatorImpl(this.xmlParser, this.xsdParser);
1717
}
1818

src/xsd/parser.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,43 @@ const runCommonTests = (xsdParser: XSDParser) => {
402402
});
403403
});
404404

405+
it('should parse books xsd', async () => {
406+
const xsd = `
407+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
408+
targetNamespace="urn:books"
409+
xmlns:bks="urn:books">
410+
411+
<xsd:element name="books" type="bks:BooksForm"/>
412+
413+
<xsd:complexType name="BooksForm">
414+
<xsd:sequence>
415+
<xsd:element name="book"
416+
type="bks:BookForm"
417+
minOccurs="0"
418+
maxOccurs="unbounded"/>
419+
</xsd:sequence>
420+
</xsd:complexType>
421+
422+
<xsd:complexType name="BookForm">
423+
<xsd:sequence>
424+
<xsd:element name="author" type="xsd:string"/>
425+
<xsd:element name="title" type="xsd:string"/>
426+
<xsd:element name="genre" type="xsd:string"/>
427+
<xsd:element name="price" type="xsd:float" />
428+
<xsd:element name="pub_date" type="xsd:date" />
429+
<xsd:element name="review" type="xsd:string"/>
430+
</xsd:sequence>
431+
<xsd:attribute name="id" type="xsd:string"/>
432+
</xsd:complexType>
433+
</xsd:schema>
434+
`;
435+
436+
await parseAndExpect(xsd, (schema) => {
437+
expect(schema.elements).toHaveLength(0);
438+
});
439+
440+
});
441+
405442
};
406443

407444
describe('XSDParser Implementations', () => {

src/xsd/standard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class XSDStandardParserImpl implements XSDParser {
99
const doc = this.xmlParser.parse(xsd);
1010

1111
// Ensure documentElement is valid
12-
if (!doc.documentElement || doc.documentElement.tagName !== "xs:schema") {
12+
if (!doc.documentElement || doc.documentElement.tagName.indexOf('schema') === -1) {
1313
throw new Error("Invalid XSD: Missing root <xs:schema>");
1414
}
1515

0 commit comments

Comments
 (0)