Multi level embedding of xml files

C

campbell.shaun

The application I am writing uses XML files for validation. I've been
able to set up my xml files so that I can share validation for common
fields using external entities. eg

<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY ch1 SYSTEM "http://www.wiz.org/project/chap1.xml">
<!ENTITY ch2 SYSTEM "http://www.wiz.org/project/chap2.xml">
<!ENTITY ch3 SYSTEM "http://www.wiz.org/project/chap3.xml">

]>

<foo>
.... document instance here ...
</foo>

....
<foo>

<BLIVET>&ch1;</BLIVET>

<BLIVET>&ch2;</BLIVET>

<BLIVET>&ch3;</BLIVET>

</foo>

This works fine but I would like to extend it so that I can include
smaller chunks of xml in the included xml file. The problem I have is
with the DOCTYPE declaration in the sub xml file which I need to
include the sub-sub xml file as I don't want this included in my top
level document.

Is it possible to do what I want to do?

Regards

Shaun
 
R

Richard Tobin

This works fine but I would like to extend it so that I can include
smaller chunks of xml in the included xml file. The problem I have is
with the DOCTYPE declaration in the sub xml file which I need to
include the sub-sub xml file as I don't want this included in my top
level document.

Is it possible to do what I want to do?

No, external entities are not complete XML files and can't have DTDs.
You will have to define the entities in the top level file. You could
modularize the top-level DTD using parameter entities in the same way
as you have modularized the document itself: put the small chunk
entity definitions in separate files like "chap1.dtd", and include
them as external parameter entities in the top-level DTD like this:

<!DOCTYPE foo [
<!ENTITY ch1 SYSTEM "http://www.wiz.org/project/chap1.xml">
<!ENTITY % ch1-ents SYSTEM "http://www.wiz.org/project/chap1.dtd">
%ch1-ents;
<!ENTITY ch2 SYSTEM "http://www.wiz.org/project/chap2.xml">
<!ENTITY % ch2-ents SYSTEM "http://www.wiz.org/project/chap2.dtd">
%ch2-ents;
....

Each of chap1.dtd, chap2.dtd, ... could use more parameter entities to
cut it into even smaller chunks.

-- Richard
 

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

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top