Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About drokulix

  • Rank
  1. Unfortunately, that's not the case...a subsequent version of the schema will allow multiple <segment/> elements, each potentially with its own start and end.It doesn't matter if start and end appear out of order as long as they are marked; order only matters if both points are unmarked, in which case the first is assumed the start.Thanks
  2. Sorry about the title...I couldn't figure out anything coherent to title the topic. Anyway, I'm new fish to Schema and I'm attempting to build a validator for XML relating to public transit.There is a root <segment> element which may contain exactly one or two of the following: <point/>, <pointStart/>, <pointEnd/>. Further, there can be at most one start, and at most one end. Since I come from a Perl background, consider the following regexp that has P standing in for <point/>, S for <pointStart/>, and E for <pointEnd/>: P?[PSE]|S[PE]|E[PS] Or, to appease certain engines that consider this nondeterministic, P[PSE]?|S[PE]?|E[PS]? The idea being that there must be one or two of them and, if two, they cannot be the same unless they are both plain <point/>s.Here is a schema that I've tested by brute force (using xmllint) to work in all cases: <?xml version="1.0" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="segment"> <xs:complexType> <xs:choice> <xs:sequence> <xs:element name="point"/> <xs:choice minOccurs="0"> <xs:element name="point"/> <xs:element name="pointStart"/> <xs:element name="pointEnd"/> </xs:choice> </xs:sequence> <xs:sequence> <xs:element name="pointStart"/> <xs:choice minOccurs="0"> <xs:element name="point"/> <xs:element name="pointEnd"/> </xs:choice> </xs:sequence> <xs:sequence> <xs:element name="pointEnd"/> <xs:choice minOccurs="0"> <xs:element name="point"/> <xs:element name="pointStart"/> </xs:choice> </xs:sequence> </xs:choice> </xs:complexType> </xs:element></xs:schema> First question: Do I really have to spell it out the way I have, or is there a simpler equivalent? The idea of removing unnecessary ordering using <xs:all/> is tantalizing, but I can't think of a way to make it work.Second question: If I wanted to replace <pointStart/> and <pointEnd/> with <point type="start"/> and <point type="end"/>, respectively, would it be possible, and how would I go about it if so? (This question is the genesis of this post. It seems messy to have to move something that's obviously an attribute into the name just to make validation possible...)Thoughts?
  • Create New...