OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Recursive section validation

[ Lists Home | Date Index | Thread Index ]

Hi

I am very much an xsd/xml newbie.  I have seen examples of recursive
definitions of xml sections that will validate xml of the general form:

  <section>
    <thing_1>...</thing_1>
    <thing_2>...</thing_2>
    <section type=folder>
      <thing_1>...</thing_1>
      <thing_2>...</thing_2>
    </section>
    <section type=folder>
      <thing_1>...</thing_1>
      <thing_2>...</thing_2>
      <section type=file>
        <thing_1>...</thing_1>
        <thing_2>...</thing_2>
      </section>
      <section type=file>
        <thing_1>...</thing_1>
        <thing_2>...</thing_2>
      </section>
    </section>
  </section>

I have a task to create an xsd for xml that is being generated by an
application that I do not control... read that as: I can not change
the format of the xml.

Things I know:

- Any "<section>" tag may have zero or more "attributes", for example:

    <section>
    <section type="foo">
    <section type="foo" id="abcdefg" srcPath="/abcd/ef/ghi">>

- If a "<section>" tag has any attributes then it will have one called
  "type=".  It can have more attributes but only one of each kind.

- Each "section" block can contain any combination of simple elements
  or other sub-sections.


Ok, for my xml-newbie brain that is more than enough to chew on.

For real "validation" though there is a complication.  The "type"
attribute is actually a hint that determines which other attributes
can or should appear in the "section" tag and it also is the key to
what "<thing...>" or sub-section elements are contained within.

Is it possible to write and xsd for this sort of recursive structure
where an attribute value drives the validation?

My instinct says no.



If I had control of the program internals that generates the xml I
might consider "promoting" the "type=" attributes up to replace the
"section" tags -- making each more unique.  As an example I'll
modify the example above:

  <section>
    <thing_1>...</thing_1>
    <thing_2>...</thing_2>
    <FOLDER>
      <thing_1>...</thing_1>
      <thing_2>...</thing_2>
    </FOLDER>
    <FOLDER>
      <thing_1>...</thing_1>
      <thing_2>...</thing_2>
      <FILE>
        <thing_1>...</thing_1>
        <thing_2>...</thing_2>
      </FILE>
      <FILE>
        <thing_1>...</thing_1>
        <thing_2>...</thing_2>
      </FILE>
    </FOLDER>
  </section>

Unfortunately, I can not do this.

Do I have any other options?




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS