JACK M
JACK M

Reputation: 2841

XQuery: computed element constructor no closing tag?

With this xqy file below I can only generate an opening rdf:RDF tag. Is computed element constructor not supposed to generate a closing tag for it?

xqy file:

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"}
}

output with zorba:

$ 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"/>

In this tutorial, each call of element generates a pair of tags.

Upvotes: 1

Views: 135

Answers (1)

JACK M
JACK M

Reputation: 2841

Found the answer by myself: I should add new elements in the element like below:

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
  }
}

The xqy file should reflect the same structure of the output file. Then the output contains the closing rdf tag:

$ 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>

Upvotes: 2

Related Questions