2016-02-25 37 views
1

通過下面的這個xqy文件,我只能生成一個開放的rdf:RDF標籤。計算的元素構造函數不應該爲它生成結束標記嗎?XQuery:計算的元素構造函數沒有結束標記?

xqy文件:

declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 
declare namespace owl="http://www.w3.org/2002/07/owl#"; 
declare namespace xsd="http://www.w3.org/2001/XMLSchema#"; 
declare namespace rdfs="http://www.w3.org/2000/01/rdf-schema#"; 

(:let $sourceDoc := "test.xsd":) 

element {xs:QName("rdf:RDF")} 
{ 
    namespace {""} {"http://www.w3.org/2002/07/owl#"}, 
    namespace {"owl"} {"http://www.w3.org/2002/07/owl#"}, 
    namespace {"xsd"} {"http://www.w3.org/2001/XMLSchema#"}, 
    namespace {"rdfs"} {"http://www.w3.org/2000/01/rdf-schema#"}, 
    attribute xml:base {"http://www.w3.org/2002/07/owl"} 
} 

輸出與左巴:

$ zorba -i -f -q test.xqy 
<?xml version="1.0" encoding="UTF-8"?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
     xmlns="http://www.w3.org/2002/07/owl" 
     xmlns:owl="http://www.w3.org/2002/07/owl" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema" 
     xml:base="http://www.w3.org/2002/07/owl"/> 

this教程,的element每個呼叫生成雙標籤。

回答

2

由我自己找到了答案: 我應該在element添加新的元素,如下面:

declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 
declare namespace owl="http://www.w3.org/2002/07/owl#"; 
declare namespace xsd="http://www.w3.org/2001/XMLSchema#"; 
declare namespace rdfs="http://www.w3.org/2000/01/rdf-schema#"; 

(:let $sourceDoc := "test.xsd":) 

element {xs:QName("rdf:RDF")} 
{ 
    namespace {""} {"http://www.w3.org/2002/07/owl#"}, 
    namespace {"owl"} {"http://www.w3.org/2002/07/owl#"}, 
    namespace {"xsd"} {"http://www.w3.org/2001/XMLSchema#"}, 
    namespace {"rdfs"} {"http://www.w3.org/2000/01/rdf-schema#"}, 
    attribute xml:base {"http://www.w3.org/2002/07/owl"}, 
    { 
    for $x in doc("test.xsd")/xs:schema/xs:element 
    return $x 
    } 
} 

的xqy文件應反映輸出文件的結構相同。然後輸出包含關閉rdf標記:

$ zorba -i -f -q test.xqy 
<?xml version="1.0" encoding="UTF-8"?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
     xmlns="http://www.w3.org/2002/07/owl" 
     xmlns:owl="http://www.w3.org/2002/07/owl" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema" 
     xml:base="http://www.w3.org/2002/07/owl"> 
    <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" 
       name="contacts"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element ref="contact"/> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
    <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" 
       name="contact"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="firstname" type="xs:NCName"/> 
     <xs:element name="lastname" type="xs:NCName"/> 
     </xs:sequence> 
     <xs:attribute name="citizen" type="xs:string"/> 
    </xs:complexType> 
    </xs:element> 
</rdf:RDF> 
+1

+1回答你自己的問題。你也可以接受你的答案。這給了其他人一個跡象表明這個問題已被接受地回答了。 –

相關問題