rdfxml-streaming-parser
Advanced tools
Comparing version 1.5.0 to 2.0.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -9,4 +9,4 @@ "use strict"; | ||
constructor(parser, message) { | ||
const saxParser = parser.saxStream._parser; | ||
super(parser.trackPosition ? `Line ${saxParser.line + 1} column ${saxParser.column + 1}: ${message}` : message); | ||
const saxParser = parser.saxParser; | ||
super(parser.trackPosition ? `Line ${saxParser.line} column ${saxParser.column + 1}: ${message}` : message); | ||
} | ||
@@ -13,0 +13,0 @@ } |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as RDF from "@rdfjs/types"; | ||
import { Tag } from "sax"; | ||
import { Transform, TransformCallback } from "stream"; | ||
import { SaxesTagNS } from "saxes"; | ||
import { Transform } from "readable-stream"; | ||
import EventEmitter = NodeJS.EventEmitter; | ||
@@ -11,6 +12,2 @@ export declare class RdfXmlParser extends Transform implements RDF.Sink<EventEmitter, RDF.Stream> { | ||
static readonly XML = "http://www.w3.org/XML/1998/namespace"; | ||
static readonly XMLNS = "http://www.w3.org/2000/xmlns/"; | ||
static readonly DEFAULT_NS: { | ||
xml: string; | ||
}; | ||
static readonly FORBIDDEN_NODE_ELEMENTS: string[]; | ||
@@ -24,5 +21,4 @@ static readonly FORBIDDEN_PROPERTY_ELEMENTS: string[]; | ||
private readonly defaultGraph?; | ||
private readonly strict?; | ||
private readonly allowDuplicateRdfIds?; | ||
private readonly saxStream; | ||
private readonly saxParser; | ||
private readonly activeTagStack; | ||
@@ -32,24 +28,2 @@ private readonly nodeIds; | ||
/** | ||
* Parse the namespace of the given tag, | ||
* and take into account the namespace of the parent tag that was already parsed. | ||
* @param {Tag} tag A tag to parse the namespace from. | ||
* @param {IActiveTag} parentTag The parent tag, or null if this tag is the root. | ||
* @return {{[p: string]: string}[]} An array of namespaces, | ||
* where the last ones have a priority over the first ones. | ||
*/ | ||
static parseNamespace(tag: Tag, parentTag?: IActiveTag): { | ||
[prefix: string]: string; | ||
}[]; | ||
/** | ||
* Expand the given term value based on the given namespaces. | ||
* @param {string} term A term value. | ||
* @param {{[p: string]: string}[]} ns An array of namespaces, | ||
* where the last ones have a priority over the first ones. | ||
* @param {RdfXmlParser} parser The RDF/XML parser instance. | ||
* @return {IExpandedPrefix} An expanded prefix object. | ||
*/ | ||
static expandPrefixedTerm(term: string, ns: { | ||
[key: string]: string; | ||
}[], parser: RdfXmlParser): IExpandedPrefix; | ||
/** | ||
* Check if the given IRI is valid. | ||
@@ -66,3 +40,3 @@ * @param {string} iri A potential IRI. | ||
import(stream: EventEmitter): RDF.Stream; | ||
_transform(chunk: any, encoding: string, callback: TransformCallback): void; | ||
_transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null, data?: any) => void): void; | ||
/** | ||
@@ -102,8 +76,8 @@ * Create a new parse error instance. | ||
* Handle the given tag. | ||
* @param {QualifiedTag} tag A SAX tag. | ||
* @param {SaxesTagNS} tag A SAX tag. | ||
*/ | ||
protected onTag(tag: Tag): void; | ||
protected onTag(tag: SaxesTagNS): void; | ||
/** | ||
* Handle the given node element in resource-mode. | ||
* @param {QualifiedTag} tag A SAX tag. | ||
* @param {SaxesTagNS} tag A SAX tag. | ||
* @param {IActiveTag} activeTag The currently active tag. | ||
@@ -113,10 +87,10 @@ * @param {IActiveTag} parentTag The parent tag or null. | ||
*/ | ||
protected onTagResource(tag: Tag, activeTag: IActiveTag, parentTag: IActiveTag, rootTag: boolean): void; | ||
protected onTagResource(tag: SaxesTagNS, activeTag: IActiveTag, parentTag: IActiveTag, rootTag: boolean): void; | ||
/** | ||
* Handle the given property element in property-mode. | ||
* @param {QualifiedTag} tag A SAX tag. | ||
* @param {SaxesTagNS} tag A SAX tag. | ||
* @param {IActiveTag} activeTag The currently active tag. | ||
* @param {IActiveTag} parentTag The parent tag or null. | ||
*/ | ||
protected onTagProperty(tag: Tag, activeTag: IActiveTag, parentTag: IActiveTag): void; | ||
protected onTagProperty(tag: SaxesTagNS, activeTag: IActiveTag, parentTag: IActiveTag): void; | ||
/** | ||
@@ -154,7 +128,2 @@ * Emit the given triple to the stream. | ||
} | ||
export interface IExpandedPrefix { | ||
local: string; | ||
uri: string; | ||
prefix: string; | ||
} | ||
export interface IRdfXmlParserArgs { | ||
@@ -174,6 +143,2 @@ /** | ||
/** | ||
* If the internal SAX parser should parse XML in strict mode, and error if it is invalid. | ||
*/ | ||
strict?: boolean; | ||
/** | ||
* If the internal position (line, column) should be tracked an emitted in error messages. | ||
@@ -189,5 +154,2 @@ */ | ||
export interface IActiveTag { | ||
ns?: { | ||
[prefix: string]: string; | ||
}[]; | ||
subject?: RDF.NamedNode | RDF.BlankNode; | ||
@@ -194,0 +156,0 @@ predicate?: RDF.NamedNode; |
@@ -5,7 +5,7 @@ "use strict"; | ||
const relative_to_absolute_iri_1 = require("relative-to-absolute-iri"); | ||
const sax_1 = require("sax"); | ||
const stream_1 = require("stream"); | ||
const saxes_1 = require("saxes"); | ||
const readable_stream_1 = require("readable-stream"); | ||
const ParseError_1 = require("./ParseError"); | ||
const rdf_data_factory_1 = require("rdf-data-factory"); | ||
class RdfXmlParser extends stream_1.Transform { | ||
class RdfXmlParser extends readable_stream_1.Transform { | ||
constructor(args) { | ||
@@ -28,82 +28,6 @@ super({ readableObjectMode: true }); | ||
} | ||
this.saxStream = sax_1.createStream(this.strict, { xmlns: false, position: this.trackPosition }); | ||
// Workaround for an issue in SAX where non-strict mode either lower- or upper-cases all tags. | ||
if (!this.strict) { | ||
this.saxStream._parser.looseCase = 'toString'; | ||
} | ||
this.saxParser = new saxes_1.SaxesParser({ xmlns: true, position: this.trackPosition }); | ||
this.attachSaxListeners(); | ||
} | ||
/** | ||
* Parse the namespace of the given tag, | ||
* and take into account the namespace of the parent tag that was already parsed. | ||
* @param {Tag} tag A tag to parse the namespace from. | ||
* @param {IActiveTag} parentTag The parent tag, or null if this tag is the root. | ||
* @return {{[p: string]: string}[]} An array of namespaces, | ||
* where the last ones have a priority over the first ones. | ||
*/ | ||
static parseNamespace(tag, parentTag) { | ||
const thisNs = {}; | ||
let hasNs = false; | ||
for (const attributeKey in tag.attributes) { | ||
if (attributeKey.startsWith('xmlns')) { | ||
if (attributeKey.length === 5) { | ||
// Set default namespace | ||
hasNs = true; | ||
thisNs[''] = tag.attributes[attributeKey]; | ||
} | ||
else if (attributeKey.charAt(5) === ':') { | ||
// Definition of a prefix | ||
hasNs = true; | ||
thisNs[attributeKey.substr(6)] = tag.attributes[attributeKey]; | ||
} | ||
} | ||
} | ||
const parentNs = parentTag && parentTag.ns ? parentTag.ns : [RdfXmlParser.DEFAULT_NS]; | ||
return hasNs ? parentNs.concat([thisNs]) : parentNs; | ||
} | ||
/** | ||
* Expand the given term value based on the given namespaces. | ||
* @param {string} term A term value. | ||
* @param {{[p: string]: string}[]} ns An array of namespaces, | ||
* where the last ones have a priority over the first ones. | ||
* @param {RdfXmlParser} parser The RDF/XML parser instance. | ||
* @return {IExpandedPrefix} An expanded prefix object. | ||
*/ | ||
static expandPrefixedTerm(term, ns, parser) { | ||
const colonIndex = term.indexOf(':'); | ||
let prefix; | ||
let local; | ||
if (colonIndex >= 0) { | ||
// Prefix is set | ||
prefix = term.substr(0, colonIndex); | ||
local = term.substr(colonIndex + 1); | ||
} | ||
else { | ||
// Prefix is not set, fallback to default namespace | ||
prefix = ''; | ||
local = term; | ||
} | ||
let uri = null; | ||
let defaultNamespace = null; | ||
for (let i = ns.length - 1; i >= 0; i--) { | ||
const nsElement = ns[i][prefix]; | ||
if (nsElement) { | ||
uri = nsElement; | ||
break; | ||
} | ||
else if (!defaultNamespace) { | ||
defaultNamespace = ns[i]['']; | ||
} | ||
} | ||
if (!uri) { | ||
// Error on unbound prefix | ||
if (prefix && prefix !== 'xmlns') { | ||
throw new ParseError_1.ParseError(parser, `The prefix '${prefix}' in term '${term}' was not bound.`); | ||
} | ||
// Fallback to default namespace if no match was found | ||
uri = defaultNamespace || ''; | ||
} | ||
return { prefix, local, uri }; | ||
} | ||
/** | ||
* Check if the given IRI is valid. | ||
@@ -122,3 +46,3 @@ * @param {string} iri A potential IRI. | ||
import(stream) { | ||
const output = new stream_1.PassThrough({ readableObjectMode: true }); | ||
const output = new readable_stream_1.PassThrough({ readableObjectMode: true }); | ||
stream.on('error', (error) => parsed.emit('error', error)); | ||
@@ -132,3 +56,3 @@ stream.on('data', (data) => output.push(data)); | ||
try { | ||
this.saxStream.write(chunk, encoding); | ||
this.saxParser.write(chunk); | ||
} | ||
@@ -158,3 +82,3 @@ catch (e) { | ||
valueToUri(value, activeTag) { | ||
return this.uriToNamedNode(relative_to_absolute_iri_1.resolve(value, activeTag.baseIRI)); | ||
return this.uriToNamedNode((0, relative_to_absolute_iri_1.resolve)(value, activeTag.baseIRI)); | ||
} | ||
@@ -188,11 +112,11 @@ /** | ||
attachSaxListeners() { | ||
this.saxStream.on('error', (error) => this.emit('error', error)); | ||
this.saxStream.on('opentag', this.onTag.bind(this)); | ||
this.saxStream.on('text', this.onText.bind(this)); | ||
this.saxStream.on('closetag', this.onCloseTag.bind(this)); | ||
this.saxStream.on('doctype', this.onDoctype.bind(this)); | ||
this.saxParser.on('error', (error) => this.emit('error', error)); | ||
this.saxParser.on('opentag', this.onTag.bind(this)); | ||
this.saxParser.on('text', this.onText.bind(this)); | ||
this.saxParser.on('closetag', this.onCloseTag.bind(this)); | ||
this.saxParser.on('doctype', this.onDoctype.bind(this)); | ||
} | ||
/** | ||
* Handle the given tag. | ||
* @param {QualifiedTag} tag A SAX tag. | ||
* @param {SaxesTagNS} tag A SAX tag. | ||
*/ | ||
@@ -214,3 +138,3 @@ onTag(tag) { | ||
for (const attributeKey in tag.attributes) { | ||
attributes += ` ${attributeKey}="${tag.attributes[attributeKey]}"`; | ||
attributes += ` ${attributeKey}="${tag.attributes[attributeKey].value}"`; | ||
} | ||
@@ -237,3 +161,2 @@ const tagContents = `${tagName}${attributes}`; | ||
this.activeTagStack.push(activeTag); | ||
activeTag.ns = RdfXmlParser.parseNamespace(tag, parentTag); | ||
if (currentParseType === ParseType.RESOURCE) { | ||
@@ -248,3 +171,3 @@ this.onTagResource(tag, activeTag, parentTag, !parentTag); | ||
* Handle the given node element in resource-mode. | ||
* @param {QualifiedTag} tag A SAX tag. | ||
* @param {SaxesTagNS} tag A SAX tag. | ||
* @param {IActiveTag} activeTag The currently active tag. | ||
@@ -255,12 +178,11 @@ * @param {IActiveTag} parentTag The parent tag or null. | ||
onTagResource(tag, activeTag, parentTag, rootTag) { | ||
const tagExpanded = RdfXmlParser.expandPrefixedTerm(tag.name, activeTag.ns, this); | ||
activeTag.childrenParseType = ParseType.PROPERTY; | ||
// Assume that the current node is a _typed_ node (2.13), unless we find an rdf:Description as node name | ||
let typedNode = true; | ||
if (tagExpanded.uri === RdfXmlParser.RDF) { | ||
if (tag.uri === RdfXmlParser.RDF) { | ||
// Check forbidden property element names | ||
if (!rootTag && RdfXmlParser.FORBIDDEN_NODE_ELEMENTS.indexOf(tagExpanded.local) >= 0) { | ||
throw this.newParseError(`Illegal node element name: ${tagExpanded.local}`); | ||
if (!rootTag && RdfXmlParser.FORBIDDEN_NODE_ELEMENTS.indexOf(tag.local) >= 0) { | ||
throw this.newParseError(`Illegal node element name: ${tag.local}`); | ||
} | ||
switch (tagExpanded.local) { | ||
switch (tag.local) { | ||
case 'RDF': | ||
@@ -282,12 +204,11 @@ // Tags under <rdf:RDF> must always be resources | ||
for (const attributeKey in tag.attributes) { | ||
const attributeValue = tag.attributes[attributeKey]; | ||
const attributeKeyExpanded = RdfXmlParser.expandPrefixedTerm(attributeKey, activeTag.ns, this); | ||
if (parentTag && attributeKeyExpanded.uri === RdfXmlParser.RDF) { | ||
switch (attributeKeyExpanded.local) { | ||
const attribute = tag.attributes[attributeKey]; | ||
if (parentTag && attribute.uri === RdfXmlParser.RDF) { | ||
switch (attribute.local) { | ||
case 'about': | ||
if (activeSubjectValue) { | ||
throw this.newParseError(`Only one of rdf:about, rdf:nodeID and rdf:ID can be present, \ | ||
while ${attributeValue} and ${activeSubjectValue} where found.`); | ||
while ${attribute.value} and ${activeSubjectValue} where found.`); | ||
} | ||
activeSubjectValue = attributeValue; | ||
activeSubjectValue = attribute.value; | ||
continue; | ||
@@ -297,6 +218,6 @@ case 'ID': | ||
throw this.newParseError(`Only one of rdf:about, rdf:nodeID and rdf:ID can be present, \ | ||
while ${attributeValue} and ${activeSubjectValue} where found.`); | ||
while ${attribute.value} and ${activeSubjectValue} where found.`); | ||
} | ||
this.validateNcname(attributeValue); | ||
activeSubjectValue = '#' + attributeValue; | ||
this.validateNcname(attribute.value); | ||
activeSubjectValue = '#' + attribute.value; | ||
claimSubjectNodeId = true; | ||
@@ -307,6 +228,6 @@ continue; | ||
throw this.newParseError(`Only one of rdf:about, rdf:nodeID and rdf:ID can be present, \ | ||
while ${attributeValue} and ${activeSubjectValue} where found.`); | ||
while ${attribute.value} and ${activeSubjectValue} where found.`); | ||
} | ||
this.validateNcname(attributeValue); | ||
activeSubjectValue = attributeValue; | ||
this.validateNcname(attribute.value); | ||
activeSubjectValue = attribute.value; | ||
subjectValueBlank = true; | ||
@@ -318,3 +239,3 @@ continue; | ||
// Emit the rdf:type later as named node instead of the default literal | ||
explicitType = attributeValue; | ||
explicitType = attribute.value; | ||
continue; | ||
@@ -329,10 +250,10 @@ case 'aboutEach': | ||
} | ||
else if (attributeKeyExpanded.uri === RdfXmlParser.XML) { | ||
if (attributeKeyExpanded.local === 'lang') { | ||
activeTag.language = attributeValue === '' ? null : attributeValue.toLowerCase(); | ||
else if (attribute.uri === RdfXmlParser.XML) { | ||
if (attribute.local === 'lang') { | ||
activeTag.language = attribute.value === '' ? null : attribute.value.toLowerCase(); | ||
continue; | ||
} | ||
else if (attributeKeyExpanded.local === 'base') { | ||
else if (attribute.local === 'base') { | ||
// SAX Parser does not expand xml:base, based on DOCTYPE, so we have to do it manually | ||
activeTag.baseIRI = relative_to_absolute_iri_1.resolve(attributeValue, activeTag.baseIRI); | ||
activeTag.baseIRI = (0, relative_to_absolute_iri_1.resolve)(attribute.value, activeTag.baseIRI); | ||
continue; | ||
@@ -343,5 +264,5 @@ } | ||
// but we ignore attributes that have no prefix or known expanded URI | ||
if (attributeKeyExpanded.prefix !== 'xml' && attributeKeyExpanded.uri) { | ||
predicates.push(this.uriToNamedNode(attributeKeyExpanded.uri + attributeKeyExpanded.local)); | ||
objects.push(attributeValue); | ||
if (attribute.prefix !== 'xml' && attribute.uri) { | ||
predicates.push(this.uriToNamedNode(attribute.uri + attribute.local)); | ||
objects.push(attribute.value); | ||
} | ||
@@ -363,3 +284,3 @@ } | ||
if (typedNode) { | ||
const type = this.uriToNamedNode(tagExpanded.uri + tagExpanded.local); | ||
const type = this.uriToNamedNode(tag.uri + tag.local); | ||
this.emitTriple(activeTag.subject, this.dataFactory.namedNode(RdfXmlParser.RDF + 'type'), type, parentTag ? parentTag.reifiedStatementId : null); | ||
@@ -407,3 +328,3 @@ } | ||
* Handle the given property element in property-mode. | ||
* @param {QualifiedTag} tag A SAX tag. | ||
* @param {SaxesTagNS} tag A SAX tag. | ||
* @param {IActiveTag} activeTag The currently active tag. | ||
@@ -413,6 +334,5 @@ * @param {IActiveTag} parentTag The parent tag or null. | ||
onTagProperty(tag, activeTag, parentTag) { | ||
const tagExpanded = RdfXmlParser.expandPrefixedTerm(tag.name, activeTag.ns, this); | ||
activeTag.childrenParseType = ParseType.RESOURCE; | ||
activeTag.subject = parentTag.subject; // Inherit parent subject | ||
if (tagExpanded.uri === RdfXmlParser.RDF && tagExpanded.local === 'li') { | ||
if (tag.uri === RdfXmlParser.RDF && tag.local === 'li') { | ||
// Convert rdf:li to rdf:_x | ||
@@ -422,11 +342,11 @@ if (!parentTag.listItemCounter) { | ||
} | ||
activeTag.predicate = this.uriToNamedNode(tagExpanded.uri + '_' + parentTag.listItemCounter++); | ||
activeTag.predicate = this.uriToNamedNode(tag.uri + '_' + parentTag.listItemCounter++); | ||
} | ||
else { | ||
activeTag.predicate = this.uriToNamedNode(tagExpanded.uri + tagExpanded.local); | ||
activeTag.predicate = this.uriToNamedNode(tag.uri + tag.local); | ||
} | ||
// Check forbidden property element names | ||
if (tagExpanded.uri === RdfXmlParser.RDF | ||
&& RdfXmlParser.FORBIDDEN_PROPERTY_ELEMENTS.indexOf(tagExpanded.local) >= 0) { | ||
throw this.newParseError(`Illegal property element name: ${tagExpanded.local}`); | ||
if (tag.uri === RdfXmlParser.RDF | ||
&& RdfXmlParser.FORBIDDEN_PROPERTY_ELEMENTS.indexOf(tag.local) >= 0) { | ||
throw this.newParseError(`Illegal property element name: ${tag.local}`); | ||
} | ||
@@ -444,16 +364,14 @@ activeTag.predicateSubPredicates = []; | ||
for (const propertyAttributeKey in tag.attributes) { | ||
const propertyAttributeValue = tag.attributes[propertyAttributeKey]; | ||
const propertyAttributeKeyExpanded = RdfXmlParser | ||
.expandPrefixedTerm(propertyAttributeKey, activeTag.ns, this); | ||
if (propertyAttributeKeyExpanded.uri === RdfXmlParser.RDF) { | ||
switch (propertyAttributeKeyExpanded.local) { | ||
const propertyAttribute = tag.attributes[propertyAttributeKey]; | ||
if (propertyAttribute.uri === RdfXmlParser.RDF) { | ||
switch (propertyAttribute.local) { | ||
case 'resource': | ||
if (activeSubSubjectValue) { | ||
throw this.newParseError(`Found both rdf:resource (${propertyAttributeValue}) and rdf:nodeID (${activeSubSubjectValue}).`); | ||
throw this.newParseError(`Found both rdf:resource (${propertyAttribute.value}) and rdf:nodeID (${activeSubSubjectValue}).`); | ||
} | ||
if (parseType) { | ||
throw this.newParseError(`rdf:parseType is not allowed on property elements with rdf:resource (${propertyAttributeValue})`); | ||
throw this.newParseError(`rdf:parseType is not allowed on property elements with rdf:resource (${propertyAttribute.value})`); | ||
} | ||
activeTag.hadChildren = true; | ||
activeSubSubjectValue = propertyAttributeValue; | ||
activeSubSubjectValue = propertyAttribute.value; | ||
subSubjectValueBlank = false; | ||
@@ -463,22 +381,22 @@ continue; | ||
if (attributedProperty) { | ||
throw this.newParseError(`Found both non-rdf:* property attributes and rdf:datatype (${propertyAttributeValue}).`); | ||
throw this.newParseError(`Found both non-rdf:* property attributes and rdf:datatype (${propertyAttribute.value}).`); | ||
} | ||
if (parseType) { | ||
throw this.newParseError(`rdf:parseType is not allowed on property elements with rdf:datatype (${propertyAttributeValue})`); | ||
throw this.newParseError(`rdf:parseType is not allowed on property elements with rdf:datatype (${propertyAttribute.value})`); | ||
} | ||
activeTag.datatype = this.valueToUri(propertyAttributeValue, activeTag); | ||
activeTag.datatype = this.valueToUri(propertyAttribute.value, activeTag); | ||
continue; | ||
case 'nodeID': | ||
if (attributedProperty) { | ||
throw this.newParseError(`Found both non-rdf:* property attributes and rdf:nodeID (${propertyAttributeValue}).`); | ||
throw this.newParseError(`Found both non-rdf:* property attributes and rdf:nodeID (${propertyAttribute.value}).`); | ||
} | ||
if (activeTag.hadChildren) { | ||
throw this.newParseError(`Found both rdf:resource and rdf:nodeID (${propertyAttributeValue}).`); | ||
throw this.newParseError(`Found both rdf:resource and rdf:nodeID (${propertyAttribute.value}).`); | ||
} | ||
if (parseType) { | ||
throw this.newParseError(`rdf:parseType is not allowed on property elements with rdf:nodeID (${propertyAttributeValue})`); | ||
throw this.newParseError(`rdf:parseType is not allowed on property elements with rdf:nodeID (${propertyAttribute.value})`); | ||
} | ||
this.validateNcname(propertyAttributeValue); | ||
this.validateNcname(propertyAttribute.value); | ||
activeTag.hadChildren = true; | ||
activeSubSubjectValue = propertyAttributeValue; | ||
activeSubSubjectValue = propertyAttribute.value; | ||
subSubjectValueBlank = true; | ||
@@ -499,3 +417,3 @@ continue; | ||
} | ||
if (propertyAttributeValue === 'Resource') { | ||
if (propertyAttribute.value === 'Resource') { | ||
parseType = true; | ||
@@ -509,3 +427,3 @@ activeTag.childrenParseType = ParseType.PROPERTY; | ||
} | ||
else if (propertyAttributeValue === 'Collection') { | ||
else if (propertyAttribute.value === 'Collection') { | ||
parseType = true; | ||
@@ -518,3 +436,3 @@ // Interpret children as being part of an rdf:List | ||
} | ||
else if (propertyAttributeValue === 'Literal') { | ||
else if (propertyAttribute.value === 'Literal') { | ||
parseType = true; | ||
@@ -527,4 +445,4 @@ // Interpret children as being part of a literal string | ||
case 'ID': | ||
this.validateNcname(propertyAttributeValue); | ||
activeTag.reifiedStatementId = this.valueToUri('#' + propertyAttributeValue, activeTag); | ||
this.validateNcname(propertyAttribute.value); | ||
activeTag.reifiedStatementId = this.valueToUri('#' + propertyAttribute.value, activeTag); | ||
this.claimNodeId(activeTag.reifiedStatementId); | ||
@@ -534,6 +452,5 @@ continue; | ||
} | ||
else if (propertyAttributeKeyExpanded.uri === RdfXmlParser.XML | ||
&& propertyAttributeKeyExpanded.local === 'lang') { | ||
activeTag.language = propertyAttributeValue === '' | ||
? null : propertyAttributeValue.toLowerCase(); | ||
else if (propertyAttribute.uri === RdfXmlParser.XML && propertyAttribute.local === 'lang') { | ||
activeTag.language = propertyAttribute.value === '' | ||
? null : propertyAttribute.value.toLowerCase(); | ||
continue; | ||
@@ -543,11 +460,11 @@ } | ||
// but we ignore attributes that have no prefix or known expanded URI | ||
if (propertyAttributeKeyExpanded.prefix !== 'xml' && propertyAttributeKeyExpanded.prefix !== 'xmlns' | ||
&& propertyAttributeKeyExpanded.uri) { | ||
if (propertyAttribute.prefix !== 'xml' && propertyAttribute.prefix !== 'xmlns' | ||
&& propertyAttribute.uri) { | ||
if (parseType || activeTag.datatype) { | ||
throw this.newParseError(`Found illegal rdf:* properties on property element with attribute: ${propertyAttributeValue}`); | ||
throw this.newParseError(`Found illegal rdf:* properties on property element with attribute: ${propertyAttribute.value}`); | ||
} | ||
activeTag.hadChildren = true; | ||
attributedProperty = true; | ||
predicates.push(this.uriToNamedNode(propertyAttributeKeyExpanded.uri + propertyAttributeKeyExpanded.local)); | ||
objects.push(this.dataFactory.literal(propertyAttributeValue, activeTag.datatype || activeTag.language)); | ||
predicates.push(this.uriToNamedNode(propertyAttribute.uri + propertyAttribute.local)); | ||
objects.push(this.dataFactory.literal(propertyAttribute.value, activeTag.datatype || activeTag.language)); | ||
} | ||
@@ -665,3 +582,3 @@ } | ||
doctype.replace(/<!ENTITY\s+([^\s]+)\s+["']([^"']+)["']\s*>/g, (match, prefix, uri) => { | ||
this.saxStream._parser.ENTITIES[prefix] = uri; | ||
this.saxParser.ENTITIES[prefix] = uri; | ||
return ''; | ||
@@ -677,6 +594,2 @@ }); | ||
RdfXmlParser.XML = 'http://www.w3.org/XML/1998/namespace'; | ||
RdfXmlParser.XMLNS = 'http://www.w3.org/2000/xmlns/'; | ||
RdfXmlParser.DEFAULT_NS = { | ||
xml: RdfXmlParser.XML, | ||
}; | ||
RdfXmlParser.FORBIDDEN_NODE_ELEMENTS = [ | ||
@@ -683,0 +596,0 @@ 'RDF', |
{ | ||
"name": "rdfxml-streaming-parser", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"description": "Streaming RDF/XML parser", | ||
@@ -35,8 +35,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/jest": "^26.0.0", | ||
"@types/jest": "^28.1.4", | ||
"@types/minimist": "^1.2.0", | ||
"@types/sax": "^1.0.1", | ||
"arrayify-stream": "^1.0.0", | ||
"arrayify-stream": "^2.0.0", | ||
"coveralls": "^3.0.0", | ||
"jest": "^27.0.1", | ||
"jest": "^28.1.2", | ||
"jest-rdf": "^1.7.0", | ||
@@ -49,6 +49,9 @@ "manual-git-changelog": "^1.0.0", | ||
"streamify-string": "^1.0.1", | ||
"ts-jest": "^27.0.1", | ||
"ts-jest": "^28.0.5", | ||
"ts-loader": "^9.3.1", | ||
"tslint": "^6.0.0", | ||
"tslint-eslint-rules": "^5.3.1", | ||
"typescript": "^4.3.5" | ||
"typescript": "^4.3.5", | ||
"webpack": "^5.73.0", | ||
"webpack-cli": "^4.10.0" | ||
}, | ||
@@ -58,3 +61,3 @@ "jest": { | ||
"ts-jest": { | ||
"tsConfig": "test/tsconfig.json" | ||
"tsconfig": "test/tsconfig.json" | ||
} | ||
@@ -93,6 +96,10 @@ }, | ||
"@rdfjs/types": "*", | ||
"@types/readable-stream": "^2.3.13", | ||
"buffer": "^6.0.3", | ||
"rdf-data-factory": "^1.1.0", | ||
"relative-to-absolute-iri": "^1.0.0", | ||
"sax": "^1.2.4" | ||
} | ||
"readable-stream": "^4.0.0", | ||
"saxes": "^6.0.0" | ||
}, | ||
"sideEffects": false | ||
} |
52863
10
7
20
803
+ Addedbuffer@^6.0.3
+ Addedreadable-stream@^4.0.0
+ Addedsaxes@^6.0.0
+ Added@types/readable-stream@2.3.15(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedreadable-stream@4.5.2(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedsaxes@6.0.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedxmlchars@2.2.0(transitive)
- Removedsax@^1.2.4
- Removedsax@1.3.0(transitive)