Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require (allow) "xml:base"-attribute in XML Schema

Tags:

xml

xsd

Given a document such as the following:

<patch xmlns="http://example.com/ns/lxfs"
       xml:base="http:/example.com/publ/lxfs"
       id="http://example.com/lxfs/patches/3">

   <!-- ... -->
</patch>

How do I write an XML Schema to require (or even allow) the presence of the xml:base attribute with the fixed value of "http://example.com/publ/lxfs" on <patch>?

This is what I'd consider the "obvious" solution but xs:attribute[@name] is supposed to an NCName:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:lxfs="http://example.com/ns/lxfs"
           xmlns:xml="http://www.w3.org/XML/1998/namespace"
           targetNamespace="http://example.com/ns/lxfs">

  <xs:element name="patch" type="lxfs:Patch" />

  <xs:complexType name="Patch">    
    <xs:attribute name="id" type="xs:anyURI" use="required" />
    <xs:attribute name="xml:base" form="qualified" fixed="http://example.com/publ/lxfs" use="required" />
  </xs:complexType>
</xs:schema>
like image 604
vicvicvic Avatar asked Apr 30 '11 17:04

vicvicvic


People also ask

How do I restrict attribute values in XML schema?

Restrictions on a Set of Values To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. Note: In this case the type "carType" can be used by other elements because it is not a part of the "car" element.

Which attribute is used to reference an XML schema?

Using schemaLocation The xsi:schemaLocation attribute works well in situations where namespace prefixes are explicitly declared and used in the XML document you want to validate. The following example shows an XML document that references an external XSD schema, MyData.

What is qualified and unqualified in XML schema?

The declaration of a target namespace gives us the possibility of defining elements and attributes that belong to the target namespace (called "qualified") and elements and attributes that don't belong to any namespace (called "unqualified").


1 Answers

Change <xs:attribute name="xml:base"> to <xs:attribute ref="xml:base">, and add an xs:import for the schema for the XML namespace which can be found at http://www.w3.org/2001/03/xml.xsd. (Use a local copy rather than a reference to the one on the W3C

like image 177
Michael Kay Avatar answered Oct 31 '22 09:10

Michael Kay