Restricting to a list
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 5
- Joined: Wed May 04, 2011 4:03 pm
Restricting to a list
Hi all!
I am wondering if it is possible to make this work with a standard schema. I'd like to create, in the XML, a list of strings, and restrict some elements to these.
For example:
I can also live without the attribute "name" restricted to the list, it can be whatever it works, a child element of string type, or anything! The important piece here is: can I restrict something to a part of the same XML, and yet being compliant with the XSD?
I am wondering if it is possible to make this work with a standard schema. I'd like to create, in the XML, a list of strings, and restrict some elements to these.
For example:
Code: Select all
<!-- these are the allowed names -->
<allowed>
<name>Bob</name>
<name>John</name>
<name>Alice</name>
</allowed>
<!-- this is ok since "Bob" is listed above -->
<who name="Bob" />
<!-- this is invalid since "Martha" isn't in the list! -->
<who name="Martha" />
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Restricting to a list
You can use identity constraints to enforce that. Here it is a working sample
test.xsd
Best Regards,
George
test.xsd
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="allowed"/>
<xs:element maxOccurs="unbounded" ref="who"/>
</xs:sequence>
</xs:complexType>
<xs:key name="allowed">
<xs:selector xpath="allowed/name"/>
<xs:field xpath="."/>
</xs:key>
<xs:keyref name="checkAllowed" refer="allowed">
<xs:selector xpath="who"/>
<xs:field xpath="@name"/>
</xs:keyref>
</xs:element>
<xs:element name="allowed">
<xs:complexType>
<xs:sequence maxOccurs="unbounded" minOccurs="0">
<xs:element ref="name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:string"/>
<xs:element name="who">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<allowed>
<name>Bob</name>
<name>John</name>
<name>Alice</name>
</allowed>
<who name="Bob" />
<who name="Martha" />
</root>
George
George Cristian Bina
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Restricting to a list
Hello,
@juanpmtz: This topic was discussing a schema issue. Can you please provide more details about your problem?
Regards,
Adrian
@juanpmtz: This topic was discussing a schema issue. Can you please provide more details about your problem?
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 3
- Joined: Thu Feb 02, 2012 5:34 pm
Re: Restricting to a list
I would like to restrict an attribute using a list but using the schema. I have done it using enumeration, like in the example below:
but i don't want to add each enumeration manually but to import the list from another xml file that i already have.
Code: Select all
<xs:attributeGroup name="functionAttributes">
<xs:attribute name="functionName" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="function1"/>
<xs:enumeration value="function2"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Restricting to a list
You can use Schematron to implement such a check, that the values are found in a specified list of values in an external XML document.
In fact there is an entire framework created on this idea, using Schematron for implementation, called genericode, developed by Anthony Coates and used in OASIS UBL standard so you may look into that.
Best Regards,
George
In fact there is an entire framework created on this idea, using Schematron for implementation, called genericode, developed by Anthony Coates and used in OASIS UBL standard so you may look into that.
Best Regards,
George
George Cristian Bina
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Restricting to a list
Then you may consider generating the XSD schemas. For example you can add an annotation in the schema when you want to have those enumerations, that point for instance to the document that contain the values and then you can have a simple XSLT that run on the schema transforms those annotations in the corresponding enumerations.
Best Regards,
George
Best Regards,
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service