Skip to content

Commit 01d9811

Browse files
Handle namespace declarations on resource nodes
1 parent 4fdb6d3 commit 01d9811

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

lib/RdfXmlParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);
306306

307307
// Interpret attributes at this point as properties on this node,
308308
// but we ignore attributes that have no prefix or known expanded URI
309-
if (attribute.prefix !== 'xml' && attribute.uri) {
309+
if (attribute.prefix !== 'xml' && attribute.prefix !== 'xmlns'
310+
&& (attribute.prefix !== '' || attribute.local !== 'xmlns')
311+
&& attribute.uri) {
310312
predicates.push(this.uriToNamedNode(attribute.uri + attribute.local));
311313
objects.push(attribute.value);
312314
}

test/RdfXmlParser-test.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,16 +930,54 @@ abc`)).rejects.toBeTruthy();
930930
]);
931931
});
932932

933-
934-
it('declaration of the namespace on the element', async () => {
933+
it('declaration of the default namespace on the property element', async () => {
935934
return expect(await parse(parser, `<?xml version="1.0"?>
936935
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
937-
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
936+
<rdf:Description rdf:about="http://example.com">
938937
<title xmlns="http://purl.org/dc/terms/" xml:lang="en">RDF1.1 XML Syntax</title>
939938
</rdf:Description>
940939
</rdf:RDF>`))
941940
.toBeRdfIsomorphic([
942-
quad('http://www.w3.org/TR/rdf-syntax-grammar',
941+
quad('http://example.com',
942+
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
943+
]);
944+
});
945+
946+
it('declaration of the namespace on the property element', async () => {
947+
return expect(await parse(parser, `<?xml version="1.0"?>
948+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
949+
<rdf:Description rdf:about="http://example.com">
950+
<dct:title xmlns:dct="http://purl.org/dc/terms/" xml:lang="en">RDF1.1 XML Syntax</dct:title>
951+
</rdf:Description>
952+
</rdf:RDF>`))
953+
.toBeRdfIsomorphic([
954+
quad('http://example.com',
955+
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
956+
]);
957+
});
958+
959+
it('declaration of the namespace on the resource element', async () => {
960+
return expect(await parse(parser, `<?xml version="1.0"?>
961+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
962+
<rdf:Description rdf:about="http://example.com" xmlns:dct="http://purl.org/dc/terms/">
963+
<dct:title xml:lang="en">RDF1.1 XML Syntax</dct:title>
964+
</rdf:Description>
965+
</rdf:RDF>`))
966+
.toBeRdfIsomorphic([
967+
quad('http://example.com',
968+
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
969+
]);
970+
});
971+
972+
it('declaration of the default namespace on the resource element', async () => {
973+
return expect(await parse(parser, `<?xml version="1.0"?>
974+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
975+
<rdf:Description rdf:about="http://example.com" xmlns="http://purl.org/dc/terms/">
976+
<title xml:lang="en">RDF1.1 XML Syntax</title>
977+
</rdf:Description>
978+
</rdf:RDF>`))
979+
.toBeRdfIsomorphic([
980+
quad('http://example.com',
943981
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
944982
]);
945983
});

0 commit comments

Comments
 (0)