Hierarchical Schema File Organization

  • Thread starter Scott Brady Drummonds
  • Start date
S

Scott Brady Drummonds

Hi, everyone,

I'm designing my first XML-based application and am stuck on an issue that I
presume is pretty simple. I'm trying to write a schema that can be used to
validate my XML file. However, I want to define components of this schema
in different files so that I can do isolated tests on these subsections. As
an example, consider this XML file:

<container>
<name>Me</name>
<object>
...
</object>
</container>

In my program, there is a class for the 'container' type and a class for the
'object' type. I'd like to be able to make a unit test for my 'object' XML
I/O as well as the 'container' XML I/O. However, to do this I need a schema
for both types. Then, to avoid redundancy, I don't want the 'container'
schema to define how the 'object' component will look. I'd prefer to have
the 'container' schema refer to the 'object' schema which will be defined in
another file.

Can this be done? If not, is there a better way to set up unit tests for my
components so that I can verify that they work in isolation before trying to
use the 'object' code in the 'container' code?

Thanks!
Scott
 
S

Scott Brady Drummonds

Scott Brady Drummonds said:
Hi, everyone,

I'm designing my first XML-based application and am stuck on an issue that I
presume is pretty simple. I'm trying to write a schema that can be used to
validate my XML file. However, I want to define components of this schema
in different files so that I can do isolated tests on these subsections. As
an example, consider this XML file:

A couple of days later I found a book that had my answer. I'm posting a
synopsis here for posterity.

The key here is the use of the <import> tag in the <schema> section. In the
top-level schema file definition, calling <import> on the file that contains
definitions that are needed and specifying the a namespace prefix for the
namespace, definitions in the other file can be referenced through the
<element> tag's "ref" attribute. Therefore definitions in one XML schema
file can be used in another.

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top