Jump to content

adding XLink to schema


pottmi

Recommended Posts

I am trying to write a schema that contains an xlink. I was able to write a DTD successfully.Please tell me what I am doing wrong...myxlink.xml:<?xml version="1.0"?><person xmlns:xlink="http://www.w3.org/1999/xlink"><homepage'>http://www.w3.org/1999/xlink"><homepage xlink:href = "my.homepage.not" /></person>myxlink.dtd: <!ELEMENT homepage (#PCDATA)> <!ATTLIST homepage xlink:type (simple) #FIXED 'simple' xlink:href CDATA #REQUIRED> <!ELEMENT person (homepage)> <!ATTLIST person xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink">myxlink.xsd:<?xml version="1.0" ?><xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/2000/10/xlink-ns"> <xs:import namespace="http://www.w3.org/2000/10/xlink-ns"/> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="homepage" type="homepage"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="homepage"> <xs:complexType> <xs:attribute name="type" type="xlink:type" use="optional" default="simple"/> <xs:attribute name="href" type="xlink:href"/> </xs:complexType> </xs:element></xs:schema># pottmi@mikepb $ xmllint --dtdvalid myxlink.dtd --noout myxlink.xml# pottmi@mikepb $ xmllint --schema myxlink.xsd --noout myxlink.xmlmyxlink.xsd:18: element attribute: Schemas parser error : Attribute decl. 'href', attribute 'type': The QName value {'http://www.w3.org/2000/10/xlink-ns', 'href'} does not resolve to a(n) simple type definition.myxlink.xsd:17: element attribute: Schemas parser error : Attribute decl. 'type', attribute 'type': The QName value {'http://www.w3.org/2000/10/xlink-ns', 'type'} does not resolve to a(n) simple type definition.myxlink.xsd:10: element element: Schemas parser error : Element decl. 'homepage', attribute 'type': The QName value {'homepage'} does not resolve to a(n) type definition.myxlink.xsd:17: element attribute: Schemas parser error : Internal error: xmlSchemaCheckAttrValConstr, type is missing... skipping validation of value constraintWXS schema myxlink.xsd failed to compile# pottmi@mikepb $

Link to comment
Share on other sites

You don't need to add XLink to the DTD, unless the complete content model of your language is written in DTD.The "type" attribute on xs:element must point to a schema data type, and you're pointing to a non existing one. If you want to refer to an element/attribute with a definition that's elsewhere in the document (or in the included document(s)) use the "ref" attribute instead.When you import a schema, you should be supplying it's location btw.If you want to enable all sorts of extension attributes on a certain element, use the <anyAttribute/> element like so:

<?xml version="1.0" ?><xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"xmlns:xlink="http://www.w3.org/2000/10/xlink-ns"><xs:element name="person"><xs:complexType><xs:sequence><xs:element ref="homepage"/></xs:sequence></xs:complexType></xs:element><xs:element name="homepage"><xs:complexType><xs:anyAttribute namespace="http://www.w3.org/2000/10/xlink-ns"/></xs:complexType></xs:element></xs:schema>

In this case, any attribute that is in the XLink's namespace is allowed.

Link to comment
Share on other sites

Cool. Learned two cool things:I read about the anyAttribute, but I did not understand why I would want to use it ( I thought it was too liberal). now I know how I can use it.Also, the ref attribute. that makes more sense than the name/type combination that I was using.Here is my current problem, as an academic exercise, I am trying to limit the the attributes to href and type.Here is the schema I am using:

<?xml version="1.0" ?><xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"		xmlns:xlink="http://www.w3.org/2000/10/xlink-ns">   <xs:element name="person">	<xs:complexType>	  <xs:sequence>		<xs:element ref="homepage"/>	  </xs:sequence>	</xs:complexType>  </xs:element>  <xs:element name="homepage">	<xs:complexType>	  <xs:attribute ref="xlink:type" use="optional" default="simple"/>	  <xs:attribute ref="xlink:href"/>	</xs:complexType>  </xs:element></xs:schema>

Here is the errors I am getting:# pottmi@mikepb $ xmllint --schema myxlink.xsd --noout myxlink.xmlmyxlink.xsd:16: element attribute: Schemas parser error : Attribute ref. 'xlink:href', attribute 'ref': The QName value {'http://www.w3.org/2000/10/xlink-ns', 'href'} does not resolve to a(n) attribute declaration.myxlink.xsd:15: element attribute: Schemas parser error : Attribute ref. 'xlink:type', attribute 'ref': The QName value {'http://www.w3.org/2000/10/xlink-ns', 'type'} does not resolve to a(n) attribute declaration.myxlink.xsd:15: element attribute: Schemas parser error : Internal error: xmlSchemaCheckAttrValConstr, type is missing... skipping validation of value constraintWXS schema myxlink.xsd failed to compileI am sure that this is some stupid newbie error, but it is not obvious to me.The anyAttribute method is definitely better than this, I am just following thru to try to get a better understanding of XML.Thanks for all of your thoughtful answers. I am learning a lot.-- Mr. Potter

Link to comment
Share on other sites

That would be impossible to do. Not like that anyway. A single schema can only target elements and attributes in a single namespace. XLink doesn't really have a schema, so you'll probably have to create your own one if you really needed that (except for the exercise, why would you?).Here's XLink's Schema (wrapped up in 3min.):

<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2000/10/xlink-ns">	<xs:attribute name="type">		<xs:simpleType>			<xs:restriction base="xs:string">				<xs:enumeration value="simple"/>				<xs:enumeration value="extended"/>				<xs:enumeration value="locator"/>				<xs:enumeration value="arc"/>				<xs:enumeration value="resource"/>				<xs:enumeration value="title"/>				<xs:enumeration value="none"/>			</xs:restriction>		</xs:simpleType>	</xs:attribute>	<xs:attribute name="href" type="xs:anyURI"/>	<xs:attribute name="show">		<xs:simpleType>			<xs:restriction base="xs:string">				<xs:enumeration value="embed"/>				<xs:enumeration value="new"/>				<xs:enumeration value="replace"/>				<xs:enumeration value="other"/>				<xs:enumeration value="none"/>			</xs:restriction>		</xs:simpleType>	</xs:attribute>	<xs:attribute name="actuate">		<xs:simpleType>			<xs:restriction base="xs:string">				<xs:enumeration value="onLoad"/>				<xs:enumeration value="onRequest"/>				<xs:enumeration value="other"/>				<xs:enumeration value="none"/>			</xs:restriction>		</xs:simpleType>	</xs:attribute></xs:schema>

save that as xlink.xsd in the same folder as your schema and add

<xs:import namespace="http://www.w3.org/2000/10/xlink-ns" schemaLocation="xlink.xsd"/>

right after the <xs:schema> opening tag.BTW, in general, creating and editing Schema is far easier with a good editor. I use Stylus Studio, and I can tell you that it rocks. I've practically learned 60% of what I know about Schema thanks to it. 30% from W3Schools, and 10% from tests and experience (yeah, I don't have much either).

Link to comment
Share on other sites

Cool. Learned two cool things:I read about the anyAttribute, but I did not understand why I would want to use it ( I thought it was too liberal). now I know how I can use it.
Note, XLink is relatively complex and flexible compared to the standard web linking model. Referece:Improving Web Linking using Xlink.There is a related book by Erik Wilde and David Lowe:"XPath, XLink, XPointer, and XML: A Practical Guide to Web Hyperlinking and Transclusion" There are two reviews at amazon:Quote from the first:"My only objection to the book is its subtitle "A practical guide...". Practical is a relative term. This book gives very valuable pointers (no pun intended) for developpers wishing to implement these technologies but it does not give very practical down to earth examples. In some other web ressources, I found for instance some XSLT code to tranform Xlink into scripting languages that simulate the xlink functionality and to tell the truth I was expecting to find this kind of material here."Important quote from the second:"This book expounds on how hyperlinks generalise the links in HTML. You can have multiple sources and multiple destinations. The links can be bidirectional. Given a destination, you can find the documents with sources that link to it. Currently, with web pages, you have to use a search engine to see who links to your pages. And no search engine reaches over 50% of the web."At least read the first document if you have not already read it. HereXML Linking Language. is another online document.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...