[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Recursive section validation

  • To: xml-dev@l...
  • Subject: Recursive section validation
  • From: Dean Karres <karres@i...>
  • Date: Thu, 27 Oct 2005 15:04:28 -0500
  • User-agent: Mutt/1.4.1i

recursively validate xml files
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?

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.