In brief: I'm looking for the best way to check that elements (in a
xml file) go in proper order and are present at expected positions and
with expected attribute "name", and if not - to understand which
elements are missing (or are excessive or are at wrong position or
have wrong attribute value).

In details:
The expected structure of my xml file is described (currently - on
paper only) in the following manner (M/O = Mandatory/Optional):

+---------------------------------+
| Element name | M/O | Attr.value |
+---------------------------------+
| A1           |  M  |            |
| A2           |  O  | ABCD       |
| Group "Z" {0,}                  |
|   A3         |  M  |            |
|   A4         |  O  |            |
| A5           |  M  | EFGH       |
| A6           |  M  |            |
+---------------------------------+

(hope that this forum uses monowidth font)

This is how it is read:

Element A1 is mandatory and must be the very first element in the
file. Then goes an optional element A2 which must have its "name"
attribute set to "ABCD". Then goes an optinal repetitive (min = 0, max
= unbounded) group "Z" of elements A3 and A4, mandatory and optional
correspondingly. Then goes a mandatory element A5 which must have its
"name" attribute set to "EFGH". And then goes a mandatory element A6
which must be the last element in the file.

And here are two samples of valid xml-files:

Sample 1:

<A1 />
<A2 name="ABCD" />
<A3 />
<A4 />
<A3 />
<A3 />
<A4 />
<A5 name="EFGH" />
<A6 />

Sample 2:

<A1 />
<A5 name="EFGH" />
<A6 />

Imagine that we have the following file of a wrong format (root
element is omitted):

*** mandatory element A1 is missing ***
<A2 name="AB" /> *** wrong attribute value ***
<A3 />
<A4 />
<B1 /> *** excessive element ***
<A6 /> *** element A6 must go after element A5, not before ***
<A5 name="EFGH" />

Ideally, I need not only understand that this file is WRONG, but also
get all these error lines enclosed in "***" symbols.

Besides, would the group "Z" be defined as "Group {1,5}", I need to
get error message "Wrong number of group occurences" (or smth. like
that) if the group occurs more than 5 times in the xml file (or
"Missing group Z" - if no group at all is found in the xml file).

I'm trying to understand what is the best (and quickest) way to solve
this task. I'm not sure that one can find a way of using xml schemas
here...

Any ideas will be appreciated! Thank you.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to