Forum Moderators: open
And unhelpful.
I am also afraid that, as seems to happen often, what should be a simple, straightforward and sensible thing [webmasterworld.com] will actually be something that isn't supported in the basic schema, and needs to be hacked to work [webmasterworld.com].
All I want to do is specify restrictions on both attributes and node value.
Simple and straightforward, yes? However, searches give me either attributes or node value.
I have found only one example [datypic.com] of schema with attributes and node value, but only the node value is restricted, and it is very strange. The restriction encompasses the attributes, which doesn't make sense to me.
Here's what I want:
<someXMLEntity attribute1="123">node value</someXMLEntity>
Where the attribute is restricted to numerical value, and there must be some string data in the node value (no empty entities).
As usual, I'll be trying to track this down, and will post anything I find, but I must be missing something. This should be simple, yes?
XML:
<complex att="123">whatever</complex>
<xs:element name="complex">
<xs:complexType mixed="true">
<xs:attribute name="att">
<xs:simpleType>
<xs:restriction base="xs:integer">
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
It will also validate this:
<complex att="123"></complex>
I haven't figured out how to require some string in the textnode... just hold on a sec
Zero examples for restricting both.
I'm using our Safari subscription to peruse "XML Schema."
I have never encountered such obscure, obsfucating, prolix vernacular as can be found in every XML tome I've ever read. I need to hire a translator just to tell me what this says. It isn't even "Academese," which I can usually decode.
perhaps you would enjoy changing your XML to look like this:
<element att="123">
<schemabites>
must be a string in here
</schemabites>
</element>
I'm trying to define the hand-offs in as pedantic and simple a manner as possible to reduce the possibility of errors.
I'll probably leave the node value unrestricted, and rely on comments to make it clear what it needs. This is being generated automatically, so the schema is really for the Japanese engineers that need to develop a software "catcher's mitt" for the output.
but it seems like someone is already working on that [schematron.com]
I don't know if I want to rely on using XSLT [w3schools.com] (which has its own standards problems) as the arbiter of my XML [w3schools.com], but this does address some key deficiencies in Schema [w3schools.com].
You are correct, Schema would benefit from improvement, but Schema itself is a big improvement over DTD [w3schools.com]. For that matter, I think XSLT would benefit from some work as well (like making a free and open source version of XSLT 2.0 available, or stop expecting everyone who uses XSLT to have 2.0 on hand).
The problem with these standards is that they are "camels." The saying is that "A camel is a horse that was designed by committee." I used to live in Morocco, and I can say that, in some cases, I'd rather have a camel handy than a horse, but a horse is a more useful critter generally.
We couldn't just decide to sit down and rewrite schema. It would get strangled in the crib, and would be a tremendous amount of work, besides.
<xs:element name="UPC_EAN">
<xs:annotation>
<xs:documentation>The UPC or EAN assigned to a specific item.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[0-9]+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Status" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="Open"/>
<xs:enumeration value="PartiallyShipped"/>
<xs:enumeration value="Complete"/>
<xs:enumeration value="Cancelled"/>
<xs:enumeration value="Hold"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Or, an example where both an attribute is defined and the textnode itself is restricted:
<xs:element name="POTotal">
<xs:annotation>
<xs:documentation>
The total monetary value represented by this PO.
The value for the Currency attribute should be drawn from the ISO 4217 standard.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="Currency" type="xs:token" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
[edited by: DrDoc at 5:12 am (utc) on Mar. 18, 2008]