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.
Also, one last thing: How do you set the max occurrence of an element
to be infinite?
Thanks in advance,
Chris
PS
I'm not posting the XSD right now. If you want it, I would be more
than happy to provide it. I am a little embarassed that I am designing
the XSD in Visual Studio 2005 instead of hand-coding it. I have no
idea if the XSD generated by VS2005 is considered to be of good
quality. 3 2095
J Hendrich wrote: "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.
Also, one last thing: How do you set the max occurrence of an element to be infinite?
maxOccurs="unbounded"
PS I'm not posting the XSD right now. If you want it, I would be more than happy to provide it. I am a little embarassed that I am designing the XSD in Visual Studio 2005 instead of hand-coding it. I have no idea if the XSD generated by VS2005 is considered to be of good quality.
I've used a few different xsd generators...I'd suggest getting familiar enough with XML Schema to know whether or not you like what it is generating. Each generator makes its own assumptions about certain things, and you won't always like what it assumes. I have only tried the XSD in VS 2003, and I don't know if it applies to the one in 2005, but the 2003 version cannot generate schemas for a broad class of XML files (whereas other generators don't have a problem). I found that to be an annoying limitation and have stayed away since.
I would like to allow items in any order in any quantity. I feel that
it might restrict thing in the future if I force you to always define
folders before files and so forth. The only restriction that I want to
place on the order is to force the <updater> node (max of 1, min of 0)
to always be the last item for a version.
I guess that I might not actually need a schema for the manifest files
since I am making a GUI to allow others to easily edit the manifest
file without needing to know all of the rules that I have or even XML.
Even if they did know XML, I am not currently validating it in the
updater using XML Schema, but rather by manually checking values.
I could make a change to the updater to force validation against a
schema, but I don't know if MSXML4 supports this, or how to access it
through VB6. Any ideas?
Do you think that a schema would actually be useful in this case?
Chris
Chris Lieb wrote: J Hendrich wrote: "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.
Also, one last thing: How do you set the max occurrence of an element to be infinite?
maxOccurs="unbounded"
PS I'm not posting the XSD right now. If you want it, I would be more than happy to provide it. I am a little embarassed that I am designing the XSD in Visual Studio 2005 instead of hand-coding it. I have no idea if the XSD generated by VS2005 is considered to be of good quality.
I've used a few different xsd generators...I'd suggest getting familiar enough with XML Schema to know whether or not you like what it is generating. Each generator makes its own assumptions about certain things, and you won't always like what it assumes. I have only tried the XSD in VS 2003, and I don't know if it applies to the one in 2005, but the 2003 version cannot generate schemas for a broad class of XML files (whereas other generators don't have a problem). I found that to be an annoying limitation and have stayed away since.
I would like to allow items in any order in any quantity. I feel that it might restrict thing in the future if I force you to always define folders before files and so forth. The only restriction that I want to place on the order is to force the <updater> node (max of 1, min of 0) to always be the last item for a version.
I guess that I might not actually need a schema for the manifest files since I am making a GUI to allow others to easily edit the manifest file without needing to know all of the rules that I have or even XML. Even if they did know XML, I am not currently validating it in the updater using XML Schema, but rather by manually checking values.
I could make a change to the updater to force validation against a schema, but I don't know if MSXML4 supports this, or how to access it through VB6. Any ideas?
Do you think that a schema would actually be useful in this case?
Chris
Ok, I got it mostly working. The elements (except <updater>) can
appear in any order in any quantity and <updater> is forced to be last
if it exists.
One last problem. The <cmd> element has a location property that can
be either 'server' or 'client'. If it is client, the contents of the
command attribute are run directly on the command line. If it is
server, I process the <file> and <folder> elements that are children of
the <cmd> element, execute the contents of the command attribute from
the application's temp directory, and then delete all of the files
created by the <file> and <folder> elements that are children of the
<cmd> node.
Is it possible to define an element that must have (greater than 1)
children of certain types if it has an attribute with one value, but
have zero children if it has an attribute with another value? If so,
how?
Chris
J Hendrich wrote: I guess that I might not actually need a schema for the manifest files since I am making a GUI to allow others to easily edit the manifest file without needing to know all of the rules that I have or even XML. Even if they did know XML, I am not currently validating it in the updater using XML Schema, but rather by manually checking values.
I could make a change to the updater to force validation against a schema, but I don't know if MSXML4 supports this, or how to access it through VB6. Any ideas?
Do you think that a schema would actually be useful in this case?
Chris
If you're only using the schema to validate that your code produces a valid manifest file (based on the user's input to your gui) that's still useful (IMHO). You don't have to put it in your application's logic to validate every file since the creation of the manifest file is under your control...but if you do have it there, you might look at it like having test/debug code to catch errors early on.
Part of the reason that I want to build validation logic into the
updater client is that I am making a quick and dirty GUI for editing
the manifest since I have four projects going and have to have them
finished by the end of June and this one is of lower priority. (That's
the problem with managers that don't understand that it is a waste of
the their and the devs' time to have to manually install every update
every time that a breeakage is encountered, which is often in this
beta-testing phase.) If I knew that I would have a decent amount of
time to work on the editor, I might forgo the schema.
As for splitting the node type, I considered it, but I don't want to
make the dialect more complicated than it needs to be :) (oops!). I
guess that splitting the node type might simplify the dialect, but I
don't have enough experience to really know.
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ruthless |
last post by:
hello.
i've got a question
can i in XML Schema define tag that works as lists knows from e.g. C,C++ -
recurrent tags?
i'm talking about e.g. genealogical tree every level of this tree is...
|
by: Olaf Meyer |
last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints
specified in the schema (e.g. constraints specified via unique element).
The validation works with the XML editor I'm using...
|
by: inquirydog |
last post by:
I am trying to store my computer network information in an xml file,
and plan to write an xml schema for the file. The general format of
the xml should be like this
<networkinfo>...
|
by: joes |
last post by:
Hello there
I tried for several days to get a simple validation with xml schema &
xerces working. Goal for me is tuse JAXP and not specific Xerces
classes. I don't get the point what I am doing...
|
by: Robert Reineri |
last post by:
Hello,
New to the XML world and .NET. I have what I believe to be a simple problem,
but I have read the .NET docs till I'm blue in the face and still can't
locate a simple example of how to...
|
by: Poonam |
last post by:
Hi,
Can some one please help me with (or point me to) a very simple but
working code sample that shows how to import XML Schema.
I have tried many samples out there on internet but nothing seems...
|
by: Dan Bass |
last post by:
There's an XML message I have, that has no namespace information.
Then there is a XSD schema that is must validate against, but this has a
targetNamespace and xmlns of...
|
by: junlia |
last post by:
We are using ACORD xml schema standard, and we need to add to it, so we
choose to redefine ACORD xml schema. One of the problems that I ran into is
how to add some values to an emumerated list.
...
|
by: Sindarian |
last post by:
This just seems like the most basic thing, but I can't find a simple
description of this process anywhere and in here, everone is talking about
going the other way :( I had .NET create an XML...
|
by: MaLec |
last post by:
I’d like to use the DataSet as the container for the XML files conforming to
some schema. The problem is, that the operation of reading the XML file into
the DataSet having its schema and then...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |