Include an xml file into another

J

jmcmejl

Hi
I have a question regarding including an xml file into another.
I have googled and found this:

Mainfile.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE adocname[
<!ENTITY anincludedfile1 SYSTEM "anincludedfile1.xml">
<!ENTITY anincludedfile2 SYSTEM "anincludedfile2.xml">
]>
<arootnode>
&anincludedfile1;
&anincludedfile2;
</arootnode>

anincludedfile1.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<anode name="test1" />

anincludedfile2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<anode name="test2" />


So far noproblem, everything works great.

But here is my problem, I would like anincludedfile1.xml to include
another xmlfile and that file might include another ant so forth.
In reallity I will probably not be very many levels but I would prefer
not having any limitations.
Applying the same technique on the other files will render an error
somethng like "You can only have one doctype".

Please help me.
/Jimmy
 
M

Martin Honnen

I have a question regarding including an xml file into another.
I have googled and found this:

Mainfile.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE adocname[
<!ENTITY anincludedfile1 SYSTEM "anincludedfile1.xml">
<!ENTITY anincludedfile2 SYSTEM "anincludedfile2.xml">
]>
But here is my problem, I would like anincludedfile1.xml to include
another xmlfile and that file might include another ant so forth.
In reallity I will probably not be very many levels but I would prefer
not having any limitations.
Applying the same technique on the other files will render an error
somethng like "You can only have one doctype".

I don't think you can solve that with external entities. Also note that
external entities are not read by non validating parsers so for instance
if you loaded your Mainfile.xml in a browser like Mozilla which uses the
Expat parser it would not load the external entities at all.

XInclude <http://www.w3.org/TR/xinclude/> might do what you want in
terms of levels but it is a new specification and has not much support
either. So unless you know you are going to process your Mainfile.xml
with a certain parser that supports XInclude there is not much use in
applying it as lots of XML parsers/tools others might use to process
your XML will not process XInclude instructions.
 
P

Peter Flynn

Hi
I have a question regarding including an xml file into another.
I have googled and found this:

Mainfile.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE adocname[
<!ENTITY anincludedfile1 SYSTEM "anincludedfile1.xml">
<!ENTITY anincludedfile2 SYSTEM "anincludedfile2.xml">
]>
<arootnode>
&anincludedfile1;
&anincludedfile2;
</arootnode>

anincludedfile1.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<anode name="test1" />

anincludedfile2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<anode name="test2" />


So far noproblem, everything works great.

But here is my problem, I would like anincludedfile1.xml to include
another xmlfile and that file might include another ant so forth.
In reallity I will probably not be very many levels but I would prefer
not having any limitations.
Applying the same technique on the other files will render an error
somethng like "You can only have one doctype".

Files included by this method must not have their own DocType
Declaration (XML Spec, section 4.3.2, production [78]).

///Peter
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top