Skip to content

Commit

Permalink
Handle namespace declarations on resource nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaspalmer committed Nov 23, 2023
1 parent 4fdb6d3 commit 01d9811
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/RdfXmlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ while ${attribute.value} and ${activeSubjectValue} where found.`);

// Interpret attributes at this point as properties on this node,
// but we ignore attributes that have no prefix or known expanded URI
if (attribute.prefix !== 'xml' && attribute.uri) {
if (attribute.prefix !== 'xml' && attribute.prefix !== 'xmlns'
&& (attribute.prefix !== '' || attribute.local !== 'xmlns')
&& attribute.uri) {
predicates.push(this.uriToNamedNode(attribute.uri + attribute.local));
objects.push(attribute.value);
}
Expand Down
46 changes: 42 additions & 4 deletions test/RdfXmlParser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,54 @@ abc`)).rejects.toBeTruthy();
]);
});


it('declaration of the namespace on the element', async () => {
it('declaration of the default namespace on the property element', async () => {
return expect(await parse(parser, `<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
<rdf:Description rdf:about="http://example.com">
<title xmlns="http://purl.org/dc/terms/" xml:lang="en">RDF1.1 XML Syntax</title>
</rdf:Description>
</rdf:RDF>`))
.toBeRdfIsomorphic([
quad('http://www.w3.org/TR/rdf-syntax-grammar',
quad('http://example.com',
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
]);
});

it('declaration of the namespace on the property element', async () => {
return expect(await parse(parser, `<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://example.com">
<dct:title xmlns:dct="http://purl.org/dc/terms/" xml:lang="en">RDF1.1 XML Syntax</dct:title>
</rdf:Description>
</rdf:RDF>`))
.toBeRdfIsomorphic([
quad('http://example.com',
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
]);
});

it('declaration of the namespace on the resource element', async () => {
return expect(await parse(parser, `<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://example.com" xmlns:dct="http://purl.org/dc/terms/">
<dct:title xml:lang="en">RDF1.1 XML Syntax</dct:title>
</rdf:Description>
</rdf:RDF>`))
.toBeRdfIsomorphic([
quad('http://example.com',
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
]);
});

it('declaration of the default namespace on the resource element', async () => {
return expect(await parse(parser, `<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="http://example.com" xmlns="http://purl.org/dc/terms/">
<title xml:lang="en">RDF1.1 XML Syntax</title>
</rdf:Description>
</rdf:RDF>`))
.toBeRdfIsomorphic([
quad('http://example.com',
'http://purl.org/dc/terms/title', '"RDF1.1 XML Syntax"@en'),
]);
});
Expand Down

0 comments on commit 01d9811

Please sign in to comment.