RDF / XML rdflib:无效的属性元素URI

时间:2016-03-02 14:04:08

标签: python xml rdf rdflib

我试图用rdflib解析python中的RDF / XML文件。该文件使用W3验证器验证OK,但是rdflib会抛出分析器错误7:6: Invalid property element URI: http://www.w3.org/1999/02/22-rdf-syntax-ns#RDF。使用此RDF转换器时会发生同样的情况(因为它也基于rdflib):http://rdf-translator.appspot.com

显然这个URI是有效的,因为它是最常用的URI之一,它可以在W3验证器中运行。我在俯瞰什么?

正如您可能从我笨拙的问题中收集到的,我是RDF和RDF / XML的新手,所以如果这很明显,我会道歉。

这是(部分)相关文件:

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <version>1.0</version>
  <totalHits>1245</totalHits>
  <records>
    <record>
      <rdf:RDF xmlns="http://kulturarvsdata.se/ksamsok#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:geoF="http://www.mindswap.org/2003/owl/geo/geoFeatures20040307.owl#" 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:time="http://www.w3.org/2006/time#">
        <Entity rdf:about="http://kulturarvsdata.se/shm/context/157">
          <ksamsokVersion>1.1</ksamsokVersion>
          <buildDate>2016-02-24</buildDate>
          <collection>Björkögravar</collection>
          <createdDate>2008-02-26</createdDate>
          <lastChangedDate>2008-02-26</lastChangedDate>
          <serviceOrganization>shm</serviceOrganization>
          <serviceName>context</serviceName>
          <url>http://mis.historiska.se/mis/sok/kontext.asp?kId=157&amp;g=1</url>
          <thumbnail>http://catview.historiska.se/catview/media/thumbnail/412519</thumbnail>
          <subject rdf:resource="http://kulturarvsdata.se/resurser/Subject#archaeology"/>
          <mediaType>text/plain</mediaType>
          <dataQuality rdf:resource="http://kulturarvsdata.se/resurser/DataQuality#raw"/>
          <itemSuperType rdf:resource="http://kulturarvsdata.se/resurser/EntitySuperType#object"/>
          <itemType rdf:resource="http://kulturarvsdata.se/resurser/EntityType#monument"/>
          <itemLicense rdf:resource="http://kulturarvsdata.se/resurser/License#cc0"/>
          <itemLicenseUrl rdf:resource="http://creativecommons.org/publicdomain/zero/1.0/"/>
          <itemName rdf:nodeID="name001"/>
          <itemLabel>Grav,</itemLabel>
          <itemSpecification rdf:nodeID="spec001"/>
          <itemDescription rdf:nodeID="desc001"/>
          <itemDescription rdf:nodeID="desc002"/>
          <itemDescription rdf:nodeID="desc003"/>
          <itemDescription rdf:nodeID="desc004"/>
          <itemDescription rdf:nodeID="desc005"/>
          <itemDescription rdf:nodeID="desc006"/>
          <itemKeyWord>Hemlanden</itemKeyWord>
          <itemKeyWord>Bj 98</itemKeyWord>
          <itemNumber rdf:nodeID="num001"/>
          <itemNumber rdf:nodeID="num002"/>
          <context rdf:nodeID="ctx001"/>
          <context rdf:nodeID="ctx002"/>
          <context rdf:nodeID="ctx003"/>
          <hasParent>http://kulturarvsdata.se/shm/site/53418</hasParent>
          <hasChild>http://kulturarvsdata.se/shm/context/158</hasChild>
          <hasChild>http://kulturarvsdata.se/shm/context/159</hasChild>
          <presentation xmlns:pres="http://kulturarvsdata.se/presentation#" rdf:parseType="Literal">
            <pres:item>
              <pres:version>1.1</pres:version>
              <pres:entityUri>http://kulturarvsdata.se/shm/context/157</pres:entityUri>
              <pres:type>Miljö</pres:type>
              <pres:id>157</pres:id>
              <pres:idLabel>Bj 98</pres:idLabel>
              <pres:itemLabel>Grav,</pres:itemLabel>
              <pres:tag>Stolpe, Hjalmar</pres:tag>
              <pres:tag>Bj 98</pres:tag>
              <pres:description>Hög . Diameter 7,5 meter, Höjd 1 meter. . .</pres:description>
              <pres:context>
                <pres:event>Datering</pres:event>
                <pres:placeLabel>Uppland Adelsö Björkö, Hemlanden</pres:placeLabel>
                <pres:timeLabel>vikingatid</pres:timeLabel>
              </pres:context>
              <pres:image>
                <pres:src type="thumbnail">http://catview.historiska.se/catview/media/thumbnail/412519</pres:src>
                <pres:src type="lowres">http://catview.historiska.se/catview/media/412519</pres:src>
                <pres:src type="highres">http://catview.historiska.se/catview/media/highres/412519</pres:src>
                <pres:byline>Hjalmar Stolpe, 2015-11-30, ATA</pres:byline>
                <pres:copyright>ATA</pres:copyright>
                <pres:mediaLicense>http://creativecommons.org/publicdomain/zero/1.0/</pres:mediaLicense>
                <pres:mediaUri>http://kulturarvsdata.se/shm/media/412519</pres:mediaUri>
                <pres:mediaUrl>http://kulturarvsdata.se/shm/media/html/412519</pres:mediaUrl>
              </pres:image>
              <pres:references>
                <hasParent>http://kulturarvsdata.se/shm/site/53418</hasParent>
                <pres:reference>http://kulturarvsdata.se/shm/context/html/158</pres:reference>
                <pres:reference>http://kulturarvsdata.se/shm/context/html/159</pres:reference>
              </pres:references>
              <pres:representations>
                <pres:representation format="HTML">http://kulturarvsdata.se/shm/context/html/157</pres:representation>
                <pres:representation format="XML">http://kulturarvsdata.se/shm/context/xml/157</pres:representation>
                <pres:representation format="RDF">http://kulturarvsdata.se/shm/context/rdf/157</pres:representation>
              </pres:representations>
              <pres:service>context</pres:service>
              <pres:organization>Statens historiska museum</pres:organization>
              <pres:organizationShort>SHM</pres:organizationShort>
              <pres:dataQuality>Rådata</pres:dataQuality>
              <pres:buildDate>2016-02-24</pres:buildDate>
            </pres:item>
          </presentation>
        </Entity>
        <Context rdf:nodeID="ctx001">
          <contextSuperType rdf:resource="http://kulturarvsdata.se/resurser/ContextSuperType#interact"/>
          <contextType rdf:resource="http://kulturarvsdata.se/resurser/ContextType#use"/>
          <contextLabel>Brukad</contextLabel>
          <fromPeriodName>vikingatid</fromPeriodName>
          <toPeriodName>vikingatid</toPeriodName>
          <fromPeriodId>p323</fromPeriodId>
          <toPeriodId>p323</toPeriodId>
          <country rdf:resource="http://kulturarvsdata.se/resurser/aukt/geo/country#SE"/>
          <geoF:county rdf:resource="http://kulturarvsdata.se/resurser/aukt/geo/county#1"/>
          <geoF:province rdf:resource="http://kulturarvsdata.se/resurser/aukt/geo/province#Up"/>
          <geoF:municipality rdf:resource="http://kulturarvsdata.se/resurser/aukt/geo/municipality#125"/>
          <geoF:parish rdf:resource="http://kulturarvsdata.se/resurser/aukt/geo/parish#1"/>
          <countyName>Stockholm</countyName>
          <provinceName>Uppland</provinceName>
          <municipalityName>Ekerö</municipalityName>
          <parishName>Adelsö</parishName>
          <placeName>Björkö, Hemlanden</placeName>
          <placeName>Hemlanden</placeName>
          <coordinates rdf:parseType="Literal">
            <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
              <gml:coordinates cs="," decimal="." ts=" ">17.5507,59.337</gml:coordinates>
            </gml:Point>
          </coordinates>
        </Context>
        <ItemNumber rdf:nodeID="num001">
          <type>Kontextnummer</type>
          <number>Bj 98</number>
        </ItemNumber>
        <ItemNumber rdf:nodeID="num002">
          <type>Kontextidentitet</type>
          <number>157</number>
        </ItemNumber>
        <ItemName rdf:nodeID="name001">
          <type>Typ</type>
          <name>Grav</name>
        </ItemName>
        <ItemSpecification rdf:nodeID="spec001">
          <type>Undertyp</type>
          <spec/>
        </ItemSpecification>
        <ItemDescription rdf:nodeID="desc001">
          <type>Gravfältszon</type>
          <desc>1E</desc>
        </ItemDescription>
        <ItemDescription rdf:nodeID="desc002">
          <type>Inre beskrivning</type>
          <desc/>
        </ItemDescription>
        <ItemDescription rdf:nodeID="desc003">
          <type>Inre gravskick</type>
          <desc/>
        </ItemDescription>
        <ItemDescription rdf:nodeID="desc004">
          <type>Undersökare</type>
          <desc>Stolpe, Hjalmar</desc>
        </ItemDescription>
        <ItemDescription rdf:nodeID="desc005">
          <type>Yttre beskrivning</type>
          <desc>Diameter 7,5 meter, Höjd 1 meter</desc>
        </ItemDescription>
        <ItemDescription rdf:nodeID="desc006">
          <type>Yttre gravskick</type>
          <desc>Hög</desc>
        </ItemDescription>
      </rdf:RDF>
      <rel:score xmlns:rel="info:srw/extension/2/relevancy-1.0">9.5520115</rel:score>
    </record>
      </records>
  <echo>
    <method>search</method>
    <startRecord>1</startRecord>
    <hitsPerPage>10</hitsPerPage>
    <query>collection="Björkögravar"</query>
  </echo>
</result>

1 个答案:

答案 0 :(得分:1)

这是因为RDF / XML文档应该以{{1​​}}开头(作为顶级XML元素),但是您的示例没有。

删除<rdf:RDF>部分之外的所有XML标记,它将解析/验证确定。

更确切地说:rdflib看到这个URI(<rdf:RDF>)出现在它需要RDF属性的地方,但是这个特定的URI被期望作为顶级XML元素,并且(显然)不能用作属性URI