Skip to content

Commit efc8f9a

Browse files
Support for CDATA in parser
1 parent a55f6ae commit efc8f9a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/RdfXmlParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export class RdfXmlParser extends Transform implements RDF.Sink<EventEmitter, RD
159159
this.saxParser.on('error', (error) => this.emit('error', error));
160160
this.saxParser.on('opentag', this.onTag.bind(this));
161161
this.saxParser.on('text', this.onText.bind(this));
162+
this.saxParser.on('cdata', this.onText.bind(this));
162163
this.saxParser.on('closetag', this.onCloseTag.bind(this));
163164
this.saxParser.on('doctype', this.onDoctype.bind(this));
164165
}

test/RdfXmlParser-test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,18 @@ abc`)).rejects.toBeTruthy();
944944
]);
945945
});
946946

947+
it('cdata support', async () => {
948+
return expect(await parse(parser, `<?xml version="1.0"?>
949+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dct="http://purl.org/dc/terms/" >
950+
<rdf:Description rdf:about="http://example.com">
951+
<dct:title><![CDATA[A title with a <tag>]]></dct:title>
952+
</rdf:Description>
953+
</rdf:RDF>`))
954+
.toBeRdfIsomorphic([
955+
quad('http://example.com',
956+
'http://purl.org/dc/terms/title', '"A title with a <tag>"'),
957+
]);
958+
});
947959

948960

949961
it('DOCTYPE and ENTITY\'s', async () => {

0 commit comments

Comments
 (0)