Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support namespace declarations on node elements and typed node elements #72

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
60 changes: 55 additions & 5 deletions test/RdfXmlParser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,20 +930,71 @@ 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'),
]);
});


it('declaration of the namespace on a typed 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#">
<dct:Standard rdf:about="http://example.com" xmlns:dct="http://purl.org/dc/terms/">
</dct:Standard>
</rdf:RDF>`))
.toBeRdfIsomorphic([
quad('http://example.com',
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://purl.org/dc/terms/Standard'),
]);
});

it('cdata support', async () => {
return expect(await parse(parser, `<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dct="http://purl.org/dc/terms/" >
Expand All @@ -957,7 +1008,6 @@ abc`)).rejects.toBeTruthy();
]);
});


it('DOCTYPE and ENTITY\'s', async () => {
return expect(await parse(parser, `<!DOCTYPE rdf:RDF
[<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
Expand Down