473,890 Members | 1,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Schema for simple XML-based scripting language

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\fil es\"
doprevious="tru e">
<file action="copy" name="text.doc"/>
<folder action="create" name="temp"/>
<updater>
<file name="update.ex e"/>
<file name="updaterli b.dll"/>
</updater>
</version>
<version major="1" minor="0" revision="0" base="1.0.0\fil es\"
doprevious="fal se">
<dll action="registe r" name="updaterli b.dll"/>
<cmd location="serve r" 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.

Jun 1 '06 #1
3 2180
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\fil es\"
doprevious="tru e">
<file action="copy" name="text.doc"/>
<folder action="create" name="temp"/>
<updater>
<file name="update.ex e"/>
<file name="updaterli b.dll"/>
</updater>
</version>
<version major="1" minor="0" revision="0" base="1.0.0\fil es\"
doprevious="fal se">
<dll action="registe r" name="updaterli b.dll"/>
<cmd location="serve r" 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="unbo unded"

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

Jun 2 '06 #2
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\fil es\"
doprevious="tru e">
<file action="copy" name="text.doc"/>
<folder action="create" name="temp"/>
<updater>
<file name="update.ex e"/>
<file name="updaterli b.dll"/>
</updater>
</version>
<version major="1" minor="0" revision="0" base="1.0.0\fil es\"
doprevious="fal se">
<dll action="registe r" name="updaterli b.dll"/>
<cmd location="serve r" 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="unbo unded"

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

Jun 2 '06 #3

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

Jun 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4626
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 the same
2
4665
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 (XMLSpy4) but not with Xerces 2.6.0. I've included a really short and simple example to illustrate it. I would like to get some comments on the validation capabilities of Xerces 2.6.0. I though it *fully* supported W3C Schema!
2
2411
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> <ipaddress>1.2.3.4</ipaddress> <hostname>qwerty</hostname> <dnsserver>7.7.7.7</dnsserver> </networkinfo>
4
5615
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 wrong. Could somebody help me? I didn't find any full example working on the net. Thank you for any hints! If I run the examples below, the parsers parses the file well, no vlaidation is occuring although the schema and xml file does not
6
3410
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 accomplish this. I have two strings (C# string type). One of them contains an XML document. The other one contains a schema.
8
2817
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 to be working. I am trying to import a complex type/simple type element type from an external xml schema. I am using xs:import tag with namespace and schemalocation attributes defined and have also declared xmlns relative to this xml schema. I...
1
2328
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 "http://www.wbf.org/xml/b2mml-v02". How do I get this XML to validate against the Schema in C#? If I use XmlSpy (2005 home edition) to perform the validation, it first inserts namespace and schema information into the XML before validating. Validation then seems to work if...
3
3619
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. For an emumerated list like this: <xsd:complexType name="AttachmentType"> <xsd:simpleContent> <xsd:restriction base="OpenEnum"> <xsd:enumeration value="040"/> <xsd:enumeration value="041"/>
4
1887
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 Schema file (xsd) for a table in my database. I then create a DataSet that contains 1 row of data from that same table. I want to use this DataSet along with the Schema file to create an XML file that ACTUALLY CONTAINS THE DATA. Simple huh: DataSet +...
2
1704
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 writing it back to the file makes it invalid, not obeying rules of this schema. Here is the simple test program performing this operation. __________________________________________________ using System; using System.Data; namespace DataSetTest
0
9822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8016
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4676
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.