1

使用 XML-Schema 可以扩展像 FOAF 这样的 rdf 词汇表,但是如何在定义中使用此类词汇表中的类?基本上我想向 foaf:person 添加新元素,并且我想确保拥有这些元素意味着这个对象是一个 foaf:Person 而不是别的。

<?xml version="1.0" encoding="UTF-8"?>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/NewXMLSchema" xmlns:foaf="http://xmlns.com/foaf/0.1/" elementFormDefault="qualified">

<xs:import foaf:namespace="http://xmlns.com/foaf/0.1/" foaf:schemaLocation="http://xmlns.com/foaf/spec/index.rdf"/>

<xs:complexType ref="foaf:Person">
    <xs:sequence>
        <xs:element name="owns">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="device">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="HereBeSomething"></xs:element>
                            </xs:sequence>
                        </xs:complexType>   
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="datapoints">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="point" type="xs:string"></xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>

复杂类型应该是 foaf:Person,但是这种排列会导致错误:

“在此行找到多个注释:- s4s-att-must-appear:属性 'name' 必须出现在元素 'complexType' 中。- s4s-att-not-allowed:属性 'ref' 不能出现在元素 'complexType' 中。 "

如何在我的新模式的定义中使用来自其他 RDF 本体的类型?

4

1 回答 1

2

我不会去那里。XML Schema 并不是处理 RDF 数据的真正好工具。许多人看到 RDF 的 XML 序列化并认为,“哦,这就像 XML 中添加了一些额外的 rdf:this 和 rdf:that 属性。” 但这是骗人的。

RDF 是一组主-谓-宾三元组。将这些三元组写入文件有多种语法。RDF/XML 就是其中之一;Turtle 和 N-Triples 和 RDFa 是其他的。

RDF/XML 的问题在于,在 RDF/XML 文件中写下同一组三元组有许多不同的方法。例如,以下两个片段是完全等价的:

<foaf:Person rdf:about="#cygri">
    <foaf:nick>cygri</foaf:nick>
</foaf:Person>

<rdf:Description rdf:ID="cygri">
    <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person">
    <foaf:nick>cygri</foaf:nick>
</foaf:Person>

总结:我的建议是不要使用 XML 工具来处理 RDF 数据。使用 RDF 工具。要扩展像 FOAF 这样的 RDF Schema,请使用 RDF Schema。

于 2011-07-27T09:07:02.433 回答