How do I fix the rdflib parse problem with a valid RDF file

I have tried all kinds of things and seem to get errors about the names spaces used within the RDF file. From what I have read, namespaces such as owl and xsd should already be defined. The code is written as a unit test and works in VSCode. I am having trouble loading the actual RDF file because the automated process keeps complaing about the content.

import FileSystem              from 'fs';
import rdflib                  from 'rdflib';
    
function unitTest ( filename )
{ console.log ( 'Starting TableOfRdfRecords.loadRdfFile -> ' + filename );
  var store        = rdflib.graph();
  var contentType  = 'application/rdf+xml';
  var baseUrl      = 'http://IoFTriples.com';
  var statement;
  var fileContents
    = FileSystem.readFileSync
      ( filename,
        'utf-8'
      );
  // console.log ( '-- fileContents BEGIN ->\n' + fileContents.split(/\r?\n/) + '\n<-- END' );
  try
  { console.log ( '-- store: "' + store
                  + '",  -- baseUrl: "' + baseUrl
                  + '", -- contentType: "' + contentType
                  + '"'
                );
    rdflib.parse ( fileContents, store, baseUrl, contentType );
    var statements = store.statementsMatching ( undefined, undefined , undefined );
    for ( var statementCounter=0; statementCounter<statements.length; statementCounter++ )
    { statement = statements [ statementCounter ];
      console.log ( statementCounter + '] ' + statement ); // the WebID of a friend
    } // End for
  }  // End try block
  catch ( errorMessage )
  { console.log ( '-- errorMessage ->\n' + errorMessage );
    console.log ( '-- statement    ->\n' + statement );
  } // End catch
  console.log ( 'Finishing TableOfRdfRecords.loadRdfFile' );
} // End function unitTest

unitTest ( './Data/Commons/Designators.rdf' );

Here is the Designators.rdf

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
	<!ENTITY cmns-av "https://www.omg.org/spec/Commons/AnnotationVocabulary/">
	<!ENTITY cmns-dsg "https://www.omg.org/spec/Commons/Designators/">
	<!ENTITY cmns-txt "https://www.omg.org/spec/Commons/TextDatatype/">
	<!ENTITY dct "http://purl.org/dc/terms/">
	<!ENTITY owl "http://www.w3.org/2002/07/owl#">
	<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
	<!ENTITY skos "http://www.w3.org/2004/02/skos/core#">
	<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
]>
<rdf:RDF xml:base="https://www.omg.org/spec/Commons/Designators/"
	xmlns:cmns-av="https://www.omg.org/spec/Commons/AnnotationVocabulary/"
	xmlns:cmns-dsg="https://www.omg.org/spec/Commons/Designators/"
	xmlns:cmns-txt="https://www.omg.org/spec/Commons/TextDatatype/"
	xmlns:dct="http://purl.org/dc/terms/"
	xmlns:owl="http://www.w3.org/2002/07/owl#"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
	xmlns:skos="http://www.w3.org/2004/02/skos/core#"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
	
	<owl:Ontology rdf:about="https://www.omg.org/spec/Commons/Designators/">
		<rdfs:label>Commons Designators Ontology</rdfs:label>
		<dct:abstract>The designators ontology defines commonly used concepts for naming, derived in part from the     patterns defined in ISO 1087 for terminology work and ISO 11179-3, Metadata Registries.  It includes several     very high level semiotic relationships, including defines, describes, and denotes for associating designators     with the concepts they reference.</dct:abstract>
		<dct:contributor>Davide Sottara, Mayo Clinic</dct:contributor>
		<dct:contributor>Dean Allemang, Working Ontologist</dct:contributor>
		<dct:contributor>Elisa Kendall, Thematix Partners LLC</dct:contributor>
		<dct:contributor>Pete Rivett, agnos.ai U.K. Ltd</dct:contributor>
		<dct:license rdf:datatype="&xsd;anyURI">http://opensource.org/licenses/MIT</dct:license>
		<owl:imports rdf:resource="https://www.omg.org/spec/Commons/AnnotationVocabulary/"/>
		<owl:imports rdf:resource="https://www.omg.org/spec/Commons/TextDatatype/"/>
		<owl:versionIRI rdf:resource="https://www.omg.org/spec/Commons/20220501/Designators/"/>
		<skos:note>The designators ontology conforms with the OWL 2 DL semantics, and is outside of OWL 2 RL due to     the inclusion of one minimum cardinality constraint (which is tyically ignored, but is important - see note on     the Designator class) and two value restrictions. These constraints can be removed if required to support OWL     RL rule-based applications that cannot be extended to support them.</skos:note>
		<cmns-av:copyright>Copyright (c) 2014-2022 Thematix Partners LLC</cmns-av:copyright>
		<cmns-av:copyright>Copyright (c) 2021-2022 Mayo Clinic</cmns-av:copyright>
		<cmns-av:copyright>Copyright (c) 2021-2022 Working Ontologist LLC</cmns-av:copyright>
		<cmns-av:copyright>Copyright (c) 2021-2022 agnos.ai U.K. Ltd</cmns-av:copyright>
		<cmns-av:copyright>Copyright (c) 2022 Object Management Group, Inc.</cmns-av:copyright>
	</owl:Ontology>
	
	<owl:Class rdf:about="&cmns-dsg;Designation">
		<rdfs:subClassOf>
			<owl:Restriction>
				<owl:onProperty rdf:resource="&cmns-txt;hasTextValue"/>
				<owl:minQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minQualifiedCardinality>
				<owl:onDataRange rdf:resource="&cmns-txt;Text"/>
			</owl:Restriction>
		</rdfs:subClassOf>
		<rdfs:subClassOf>
			<owl:Restriction>
				<owl:onProperty rdf:resource="&cmns-dsg;denotes"/>
				<owl:someValuesFrom rdf:resource="&owl;Thing"/>
			</owl:Restriction>
		</rdfs:subClassOf>
		<rdfs:label>designation</rdfs:label>
		<dct:source>ISO 1087 Terminology work and terminology science - Vocabulary, Second edition, 2019-09, clause 3.    4.1</dct:source>
		<skos:definition>representation for someone or something by a sign that denotes it</skos:definition>
		<skos:note>A designation can be a term including appellations, a proper name, or a symbol.</skos:note>
		<skos:note>A designation can be linguistic or non-linguistic. It can consist of various types of characters,     but also punctuation marks such as hyphens and parentheses, governed by domain-, subject-, or     language-specific conventions.</skos:note>
		<skos:note>Note that the use of the min 0 cardinality restriction in the definition of this class is provided     as a reminder that designators are expected, in many cases, to have a text value associated with them. There     are cases where this is not true, however, including symbols.  And, there may be cases where the value is not     known. Additionally, not all tools support rdf:langString, thus its use in the definition of the Text datatype     may cause errors, for example in value and some number restrictions. Min 0 cardinality constraints are ignored     by reasoners and other processors, so this allows us to say that the possible values for this property are     likely either xsd:string or rdf:langString, but does not require it depending on the environment in which the     ontology is deployed.</skos:note>
		<cmns-av:synonym>designator</cmns-av:synonym>
	</owl:Class>
	
	<owl:Class rdf:about="&cmns-dsg;Name">
		<rdfs:subClassOf rdf:resource="&cmns-dsg;Designation"/>
		<rdfs:subClassOf>
			<owl:Restriction>
				<owl:onProperty rdf:resource="&cmns-dsg;isNameOf"/>
				<owl:someValuesFrom rdf:resource="&owl;Thing"/>
			</owl:Restriction>
		</rdfs:subClassOf>
		<rdfs:label>name</rdfs:label>
		<dct:source>ISO/IEC 11179-3 Information technology - Metadata registries (MDR) - Registry metamodel and basic     attributes, Third edition, 2013-02-15</dct:source>
		<skos:definition>distinctive designation for an individual (person, organization or thing)</skos:definition>
	</owl:Class>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;defines">
		<rdfs:label>defines</rdfs:label>
		<rdfs:seeAlso rdf:resource="https://plato.stanford.edu/entries/definitions/"/>
		<owl:inverseOf rdf:resource="&cmns-dsg;isDefinedIn"/>
		<skos:definition>specifies the meaning of something in terms of one or more of its essential qualities</    skos:definition>
		<skos:note>A quality is an elementary characteristic of something. An &apos;essential quality&apos; is one     that provides a necessary criteria for being that thing and differentiating criteria for not being something     else.</skos:note>
	</owl:ObjectProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;denotes">
		<rdfs:label>denotes</rdfs:label>
		<rdfs:domain rdf:resource="&cmns-dsg;Designation"/>
		<rdfs:seeAlso rdf:resource="http://www.ontologydesignpatterns.org/cp/owl/semiotics.owl#"/>
		<rdfs:seeAlso rdf:resource="https://www.w3.org/2016/05/ontolex/"/>
		<skos:definition>serves as a sign for something</skos:definition>
		<skos:note>Note that in some references, such as the semiotics ontology from Ontology Design Patterns,&apos;    denotes&apos; can be used to talk about e.g. entities denoted by proper nouns: the proper noun &apos;Leonardo     da Vinci&apos; denotes the person Leonardo da Vinci; as well as to talk about sets of entities that can be     described by a common noun: the common noun &apos;person&apos; denotes the collection of all persons in a     domain of discourse. Other references that may be useful for interpreting &apos;denotes&apos; include OntoLex.     The interpretation of &apos;denotes&apos; in this context is more general, but intended to reflect its usage     in the semiotic triangle.</skos:note>
	</owl:ObjectProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;describes">
		<rdfs:label>describes</rdfs:label>
		<owl:inverseOf rdf:resource="&cmns-dsg;isDescribedBy"/>
		<skos:definition>conveys the nature of</skos:definition>
	</owl:ObjectProperty>
	
	<owl:DatatypeProperty rdf:about="&cmns-dsg;hasDescription">
		<rdfs:subPropertyOf rdf:resource="&cmns-txt;hasTextValue"/>
		<rdfs:label>has description</rdfs:label>
		<skos:definition>provides a textual statement, picture in words, or account that describes something</    skos:definition>
		<skos:note>Note that the hasDescription property defined herein has an implicit range of rdfs:Literal. This is     purposeful, so that users can specify any element that has a name with or without a language tag without     concern for conflicting datatypes (i.e., xsd:string vs. rdf:langString, which are logically disjoint).</    skos:note>
	</owl:DatatypeProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;hasName">
		<rdfs:subPropertyOf rdf:resource="&cmns-dsg;isSignifiedBy"/>
		<rdfs:label>has name</rdfs:label>
		<rdfs:range rdf:resource="&cmns-dsg;Name"/>
		<owl:inverseOf rdf:resource="&cmns-dsg;isNameOf"/>
		<skos:definition>is known by</skos:definition>
	</owl:ObjectProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;isDefinedIn">
		<rdfs:label>is defined in</rdfs:label>
		<skos:definition>indicates something that specifies the meaning associated with the subject</skos:definition>
		<skos:note>Typically, a concept, such as a classifier or identifier, will be defined in terms of a scheme,     contract, specification, standard, or other reference.</skos:note>
	</owl:ObjectProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;isDescribedBy">
		<rdfs:label>is described by</rdfs:label>
		<skos:definition>has general nature or description of</skos:definition>
	</owl:ObjectProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;isNameOf">
		<rdfs:subPropertyOf rdf:resource="&cmns-dsg;denotes"/>
		<rdfs:label>is name of</rdfs:label>
		<rdfs:domain rdf:resource="&cmns-dsg;Name"/>
		<skos:definition>denotes in some context</skos:definition>
	</owl:ObjectProperty>
	
	<owl:ObjectProperty rdf:about="&cmns-dsg;isSignifiedBy">
		<rdfs:label>is signified by</rdfs:label>
		<rdfs:range rdf:resource="&cmns-dsg;Designation"/>
		<owl:inverseOf rdf:resource="&cmns-dsg;denotes"/>
		<skos:definition>has representation, denotation or sign of</skos:definition>
	</owl:ObjectProperty>

</rdf:RDF>

here are the results of the unitTest

 [Running] node "/Users/robertstavros/Documents/TemplateFoundryJS/Code/aaa_test.js"
 Starting TableOfRdfRecords.loadRdfFile -> ./Data/Commons/Designators.rdf
 -- store: "{}",  -- baseUrl: "http://IoFTriples.com", -- contentType: "application/rdf+xml"
 [xmldom error]	entity not found:&xsd; 
 @#[line:31,col:3]
 [xmldom error]	entity not found:&xsd; 
 @#[line:47,col:5]
 [xmldom error]	entity not found:&owl; 
 @#[line:54,col:5]
 [xmldom error]	entity not found:&owl; 
 @#[line:71,col:5]
 -- errorMessage ->
 Error: Error: NamedNode IRI "&xsd;anyURI" must be absolute. while trying to parse <http://IoFTriples.com> as      application/rdf+xml
 -- statement    ->
 undefined
 Finishing TableOfRdfRecords.loadRdfFile
 
 [Done] exited with code=0 in 0.726 seconds

I might be wrong, but it might be because: XML Schema is only available in xml, html, or dtd, not an rdf content type like text/turtle or n3, etc

I’m sure Jesse will pop in with the answer, he always knows stuff like this

My first port of call would be to try parsing it using GitHub - rubensworks/rdf-parse.js: Parses RDF from any serialization (which is using GitHub - rdfjs/rdfxml-streaming-parser.js: Streaming RDF/XML parser under the hood in the case of parsing rdfxml) - that can help rule out any issues with one of the parsers not being spec compliant.

That said, I would avoid using rdfxml in the context of Solid since it is not well supported (for instance there aren’t any spec compliant rdfxml serialisers that I know of in JavaScript). Similarly I can’t verify your Designators.rdf is spec compliant with rdfxml without having to refer back to the spec.

1 Like