![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - RE: Schema for simple XML-based scripting language [Thread Next] RE: Schema for simple XML-based scripting languageTo: NULL Date: 6/2/2006 7:04:00 AM > > "Chris Lieb" wrote: > > > I am new to XML Schema and am running into a bit of a snag. I have > > defined an XML-based scripting language for an updater program that I > > am working on. I would like to make a schema for this language since > > malformed XML documents break the updater. (I did not have time to add > > good error-handling code, so run-time errors can abound if the document > > is malformed.) > > > > A sample doc might look something like this: > > > > <manifest> > > <version major="1" minor="0" revision="1" base="1.0.1\files\" > > doprevious="true"> > > <file action="copy" name="text.doc"/> > > <folder action="create" name="temp"/> > > <updater> > > <file name="update.exe"/> > > <file name="updaterlib.dll"/> > > </updater> > > </version> > > <version major="1" minor="0" revision="0" base="1.0.0\files\" > > doprevious="false"> > > <dll action="register" name="updaterlib.dll"/> > > <cmd location="server" command="patch.bat"> > > <file name="patch.dat"/> > > <file name="patch.bat"/> > > </cmd> > > </version> > > </manifest> > > > > Problem is that the second version element in the document, the updater > > element, the dll element, and the cmd element all get flagged as > > invalid. I guess that this stems from using a sequence in the complex > > type. What should I use to allow all children elements of version > > (file, folder, dll, msi, cmd, updater) to appear in any order and in > > whatever quantity (except updater, which can only appear once)? > > > > 'all' looks like it comes close since it allows you to use elements in > > any order, except my reading tells me that it only allows each element > > to be used once and forces you to use all elements. 'choice' also > > appears to come close since it allows you to choose which element you > > want, but it only lets you choose one element from the set. > > > > Are you certain you need to allow for all possible combinations of all > elements in any order...if you can whittle down the possible combinations to > only those combinations that should be allowed to occur you can use > xs:sequence embedded inside of xs:choice, like: > > <xs:choice> > <xs:sequence> > <xs:element ref="dll"/> > <xs:element ref="cmd"/> > </xs:sequence> > <xs:sequence> > <xs:element ref="file"/> > <xs:element ref="folder"/> > <xs:element ref="updater"/> > </xs:sequence> > </xs:choice> > > If indeed all possible combinations are possible, then the above is not a > very attractive solution. > The above is not a good way in retrospect...look at mavis's post of 5/31/06. Put all possible sub-elements of version into a <xs:choise maxOccurs="unbounded">. mavis suggests the XML processor may be a long time doing such validation, but that may not be of concern to you in your application. | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
