RMLio / RML-Processor

16 stars 13 forks source link

XML namespace needs to be declared in XML file? #19

Closed mcm104 closed 2 years ago

mcm104 commented 2 years ago

Hello!

I'm having trouble writing maps for our prefixed XML, specifically when it comes to attributes with the prefix xml:.

Here is a sample of our XML data:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
   xmlns:rdaw="http://rdaregistry.info/Elements/w/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
   <rdf:Description rdf:about="http://example.org/example">
      <rdaw:P10223 xml:lang="ru">Zapiski iz mertvogo doma</rdaw:P10223>
   </rdf:Description>
</rdf:RDF>

Here is the RML map I have written:

@prefix bf: <http://id.loc.gov/ontologies/bibframe/>.
@prefix ex: <http://example.org/rules/>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.

ex:ExampleMap a rr:TriplesMap;
   rml:logicalSource [
      rml:source "RML_demo_data.xml";
      rml:referenceFormulation ql:XPath;
      rml:iterator "/rdf:RDF/rdf:Description"
   ];

   rr:subjectMap [
      rml:reference "@rdf:about";
      rr:class bf:Work
   ];

   rr:predicateObjectMap [
      rr:predicate bf:title;
      rr:objectMap [
         rml:reference "rdaw:P10223";
         rr:termType rr:Literal;
         rml:languageMap [
            rml:reference "rdaw:P10223/@xml:lang"
         ]
      ]
   ].

When I run this through the mapper, this is the output:

javax.xml.transform.TransformerException: Prefix must resolve to a namespace: xml
    at java.xml/com.sun.org.apache.xpath.internal.compiler.XPathParser.error(XPathParser.java:621)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:637)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:360)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:99)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:115)
    at java.xml/com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:178)
    at java.xml/com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
    at java.xml/com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:162)
    at be.ugent.rml.records.XMLRecord.get(XMLRecord.java:49)
    at be.ugent.rml.extractor.ReferenceExtractor.extract(ReferenceExtractor.java:31)
    at be.ugent.rml.extractor.ReferenceExtractor.execute(ReferenceExtractor.java:41)
    at be.ugent.rml.termgenerator.LiteralGenerator.lambda$generate$0(LiteralGenerator.java:67)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at be.ugent.rml.termgenerator.LiteralGenerator.generate(LiteralGenerator.java:63)
    at be.ugent.rml.Executor.generatePredicateObjectGraphs(Executor.java:277)
    at be.ugent.rml.Executor.executeWithFunctionV5(Executor.java:233)
    at be.ugent.rml.Executor.executeV5(Executor.java:152)
    at be.ugent.rml.cli.Main.main(Main.java:369)
    at be.ugent.rml.cli.Main.main(Main.java:44)
--------------- linked to ------------------
javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Prefix must resolve to a namespace: xml
    at java.xml/com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:170)
    at be.ugent.rml.records.XMLRecord.get(XMLRecord.java:49)
    at be.ugent.rml.extractor.ReferenceExtractor.extract(ReferenceExtractor.java:31)
    at be.ugent.rml.extractor.ReferenceExtractor.execute(ReferenceExtractor.java:41)
    at be.ugent.rml.termgenerator.LiteralGenerator.lambda$generate$0(LiteralGenerator.java:67)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at be.ugent.rml.termgenerator.LiteralGenerator.generate(LiteralGenerator.java:63)
    at be.ugent.rml.Executor.generatePredicateObjectGraphs(Executor.java:277)
    at be.ugent.rml.Executor.executeWithFunctionV5(Executor.java:233)
    at be.ugent.rml.Executor.executeV5(Executor.java:152)
    at be.ugent.rml.cli.Main.main(Main.java:369)
    at be.ugent.rml.cli.Main.main(Main.java:44)
Caused by: javax.xml.transform.TransformerException: Prefix must resolve to a namespace: xml
    at java.xml/com.sun.org.apache.xpath.internal.compiler.XPathParser.error(XPathParser.java:621)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:637)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:360)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:99)
    at java.xml/com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:115)
    at java.xml/com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:178)
    at java.xml/com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
    at java.xml/com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:162)
    ... 11 more
@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .

<http://example.org/example> a bf:Work .

I thought this was strange, because the XML namespace according to W3C doesn't need to be declared, but the XPath parser used here is giving me an error. Sure enough, if I do declare the namespace:

Modified XML data:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
   xmlns:rdaw="http://rdaregistry.info/Elements/w/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:xml="http://www.w3.org/XML/1998/namespace"
>
   <rdf:Description rdf:about="http://example.org/example">
      <rdaw:P10223 xml:lang="ru">Zapiski iz mertvogo doma</rdaw:P10223>
   </rdf:Description>
</rdf:RDF>

And I keep the RML the same, I get my desired output:

@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .

<http://example.org/example> a bf:Work;
   bf:title "Zapiski iz mertvogo doma"@ru .

I guess I'm wondering if this is an RML Mapper issue, an issue with this particular XPath parser, or if we're just going to have to go through all of our data and declare that XML namespace even though we shouldn't have to... Any thoughts or suggestions?

Thanks in advance!

mcm104 commented 2 years ago

Left this in the wrong repository -- my apologies!