我想创建一个读取外部映射RDF文件(http://zbw.eu/stw/versions/latest/mapping/dbpedia/about.en.html)的程序。
RDF文件如下所示。
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:cc="http://creativecommons.org/ns#" xmlns:dbr="http://dbpedia.org/resource/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:foaf="http://xmlns.com/foaf/0.1/" 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:void="http://rdfs.org/ns/void#" xmlns:waiver="http://vocab.org/waiver/terms/" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xml:base="http://zbw.eu/stw/mapping/dbpedia">
<rdf:Description rdf:about="../descriptor/17782-1">
<skos:inScheme rdf:resource="../../stw"/>
</rdf:Description>
<rdf:Description rdf:about="../descriptor/14066-0">
<skos:prefLabel xml:lang="de">Kokosnuss</skos:prefLabel>
</rdf:Description>
<rdf:Description rdf:about="../descriptor/14066-0">
<skos:prefLabel xml:lang="en">Coconut</skos:prefLabel>
</rdf:Description>
<rdf:Description rdf:about="../descriptor/26226-2">
<skos:inScheme rdf:resource="../../stw"/>
</rdf:Description>
<rdf:Description rdf:about="../descriptor/18847-1">
<skos:inScheme rdf:resource="../../stw"/>
</rdf:Description>
我使用Apache Jena API编写了程序。
String fileName = "stw_dbpedia_mapping.rdf";
String STW = "";
Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open(fileName);
model.read(in, "RDF/XML");
但是,我收到以下错误。
Exception in thread "main" com.hp.hpl.jena.shared.JenaException: org.xml.sax.SAXParseException: Open quote is expected for attribute "rdf:about" associated with an element type "rdf:Description".
at com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler.fatalError(RDFDefaultErrorHandler.java:58)
at com.hp.hpl.jena.rdf.arp.impl.ARPSaxErrorHandler.fatalError(ARPSaxErrorHandler.java:48)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.warning(XMLHandler.java:209)
at com.hp.hpl.jena.rdf.arp.impl.XMLHandler.fatalError(XMLHandler.java:239)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.scanAttributeValue(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanAttribute(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
程序可以读取其他类型的RDF文件......