[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [xml] can I do _this_ with AttType?



Hi,

On Tue, 2005-06-07 at 07:33 -0600, Sebastian Kuzminsky wrote:
> Aron Stansvik <elvstone gmail com> wrote:
> > On 6/1/05, Sebastian Kuzminsky <seb highlab com> wrote:
> > > All good and well so far.  But now I want to limit the values that
> > > set's id can take.
> > 
> > This is not a libxml2-specific question, but I think you'll need to
> > use XML Schemas [1], Relax NG or something else than DTDs to do this.
> > DTDs lacks the sufficient expressive power for restricting attribute
> > values to regular expressions.
> 
> Thanks for the info & the pointers!

I'll try to give an example for XML Schemata with identity-constraints
(IDC), since ID/IDREF is currently not implemented in Libxml2's XS
processor.

idc.xsd
-------
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  targetNamespace="urn:test:foo"
  xmlns:f="urn:test:foo">

  <xsd:element name="foo">
    <xsd:unique name="fooKey">
      <xsd:selector xpath="f:set"/>
	<xsd:field xpath="@id"/>
    </xsd:unique>
  </xsd:element>

  <xsd:element name="set">
    <xsd:complexType>
      <xsd:attribute name="id" use="required">
	<xsd:simpleType>
	  <xsd:restriction base="xsd:string">
	    <xsd:pattern value="[-a-zA-Z0-9]"/>
	  </xsd:restriction>
	</xsd:simpleType>
      </xsd:attribute>
    </xsd:complexType>		
  </xsd:element>

</xsd:schema> 

idc.xml
-------
<f:foo xmlns:f="urn:test:foo"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
	xsi:schemaLocation="urn:test:foo idc.xsd">
	<f:set id="a"/>
	<f:set id="J"/>
	<f:set id="5"/>
	<f:set id="J"/>
</f:foo>

xmllint --noout --schema idc.xsd idc.xml
Element '{urn:test:foo}set': Duplicate key-sequence ['J'].

Regards,

Kasimier




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]