Nivaldo,

Namespaces are very useful when working with schemas. However, I find that this works: note that the root xs:schema element has no targetNamespace attribute.

(: in Schemas :)
xdmp:document-insert(
  'test.xsd',
<xs:schema
 attributeFormDefault="unqualified"
 elementFormDefault="unqualified"
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 xmlns="http://marklogic.com/tutorial";>
  <xs:element name="name" type="xs:token"
   abstract="false" nillable="false"/>
  <xs:element name="qualification" type="xs:token"
   abstract="false" nillable="false"/>
  <xs:element name="born" type="xs:date"
   abstract="false" nillable="false"/>
  <xs:element name="dead" type="xs:date"
   abstract="false" nillable="false"/>
  <xs:element name="isbn" type="xs:unsignedLong"
   abstract="false" nillable="false"/>
  <xs:attribute name="id" type="xs:ID"/>
  <xs:attribute name="available" type="xs:boolean"/>
  <xs:attribute name="lang" type="xs:language"/>
  <xs:element name="title" abstract="false" nillable="false">
    <xs:complexType mixed="false">
      <xs:simpleContent>
        <xs:extension base="xs:token">
          <xs:attribute ref="lang" use="optional"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="library" abstract="false" nillable="false">
    <xs:complexType mixed="false">
      <xs:sequence minOccurs="1" maxOccurs="1">
        <xs:element ref="book" maxOccurs="unbounded" minOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="author" abstract="false" nillable="false">
    <xs:complexType mixed="false">
      <xs:sequence minOccurs="1" maxOccurs="1">
        <xs:element ref="name" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="born" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="dead" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
      <xs:attribute ref="id" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="book" abstract="false" nillable="false">
    <xs:complexType mixed="false">
      <xs:sequence minOccurs="1" maxOccurs="1">
        <xs:element ref="isbn" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="title" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="author" minOccurs="0"
   maxOccurs="unbounded"/>
        <xs:element ref="character" minOccurs="0"
   maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute ref="id" use="optional"/>
      <xs:attribute ref="available" use="optional"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="character" abstract="false" nillable="false">
    <xs:complexType mixed="false">
      <xs:sequence minOccurs="1" maxOccurs="1">
        <xs:element ref="name" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="born" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="qualification" minOccurs="1"
   maxOccurs="1"/>
      </xs:sequence>
      <xs:attribute ref="id" use="optional"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
)

(: in content database :)
import schema ''
  at 'test.xsd';
xdmp:describe(data(<book available="0"/>/@available))
=> false()

Without the schema, the query would return xs:untypedAtomic("0"). Note that the 'import schema...' prologue declaration isn't strictly necessary, but might be helpful if you have more than one namespace-free schema in your Schemas database.

-- Mike

On 2009-08-21 13:31, Fernandes, Nivaldo wrote:
Hi Michael,

In your tutorial at 
http://developer.marklogic.com/howto/tutorials/2007-04-schema.xqy you write:
“Before we get started, there's one more thing we should know about XML Schema 
and MarkLogic Server. They work best when our XML uses a default element 
namespace. Schemas can have a target namespace, so setting a default element 
namespace allows us to have multiple schemas, and automatically apply the 
correct schema to the correct content.”

Since you did not say it was NOT possible to use a schema without a target 
namespace (sorry for the double negative), I looked it up in the Admin and 
Developer’s guide for a way to do it…but could not find it (or perhaps it was 
there and I did not see it). Could you clarify if is possible to make use of a 
schema without a target namespace in ML 4.1 and if so, how?

Thanks!
Nivaldo



_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to