By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

How to include/insert one XML file into another?

P: n/a
Hello,

how can I transparently insert one XML file into another? I am looking
for a method simmilar to the #include <file> known from the C language.
To be more precise, an example:

I have one file:

MainDocument.xml
<Document>
<Person>
<Name>Mr X</Name>
<Biography>His life was very long and boring.</Biography>
</Person>
<Person>
<Name>Mr Y</Name>
<Biography>His life was very long too.</Biography>
</Person>
</Document>

And need to have three files, something like this:

MainDocument.xml
<Document>
<Person>
<Name>Mr X</Name>
<Include filename="MrX.xml"/> <!--That is the question-->
</Person>
<Person>
<Name>Mr Y</Name>
<Include filename="MrY.xml"/> <!--That is the question-->
</Person>
</Document>

MrX.xml
<Biography>His life was very long and boring.</Biography>

MrY.xml
<Biography>His life was very long too.</Biography>
The desired construction/method should just replace the link (eg.
<Include> element) with the content of the proper file. And the most
important is to make the parser/validator recognizes the
MainDocument.xml file as valid in both variants, using one schema for
them; in other words: including or linking should be transparent for the
parser (assumming, that all included files are accessible).

I suppose that my question is very basic, I've tried to find an answer
with Google (XML link, include, insert, embed etc.) but failed. Could
you give me a hint?

Thanks,
Wojtek
Apr 6 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Wojtek wrote:
how can I transparently insert one XML file into another? [...] I suppose that my question is very basic, I've tried to find an answer
with Google (XML link, include, insert, embed etc.) but failed. Could
you give me a hint?


XInclude
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Apr 6 '06 #2

P: n/a
Johannes Koch wrote:
how can I transparently insert one XML file into another?


XInclude


Or a suitable XSLT stylesheet. Or a bit of simple DOM or SAX
programming. Or...

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 6 '06 #3

P: n/a
Joseph Kesselman wrote:
Johannes Koch wrote:
how can I transparently insert one XML file into another?
XInclude


Or a suitable XSLT stylesheet. Or a bit of simple DOM or SAX
programming. Or...


Johannes, Joseph - thank you very much :)

Unfortunately, I am afraid that the problem remains unresolved :(

My intention is to avoid additional programming at all and not to change
existing schemas and transformations. (And I don't use DTD entities).
XInclude seems to be the most elegant and simple method, but it is not
neutral for the parsing or xsl transformation... To use XInclude i have
to rewrite my XML schema and implement XIncluding there. The same with
transformation.

<Document
xmlns="IncludeExample"
xsi:schemaLocation="IncludeExample IncludeExample.xsd"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


<Person>
<Name>Mr X</Name>
<Biography>His life was very long and boring.</Biography>
</Person>

<Person>
<Name>Mr Y</Name>
<xi:include href="MrY.xml)" parse="xml"/>
</Person>

</Document>

In the example above there is no equivalence between the case of Mr X
and Mr Y. And what I am looking for is to make the parser treats both
cases in the same way, what means:

(
insert MrY.xml file content instead of <xi:include/> tag
or
insert <Biography> element from that file using xpointer(/Biography)
)
and
parse it as a (further) content of the <Person> element, just as the
<Biography> element in the Mr X case.

I start to think that's impossible. Am I right?

Apr 7 '06 #4

P: n/a
A little explanation:
to make the parser treats both cases in the same way
By these words I mean not to modify parser program, but to modify only
the XML file(s).
A little corrigendum:
<xi:include href="MrY.xml)" parse="xml"/>


Additonal right bracket in the example code is a typing mistake only.
Apr 7 '06 #5

P: n/a
Wojtek wrote:
In the example above there is no equivalence between the case of Mr X
and Mr Y. And what I am looking for is to make the parser treats both
cases in the same way, what means:

(
insert MrY.xml file content instead of <xi:include/> tag
or
insert <Biography> element from that file using xpointer(/Biography)
)
and
parse it as a (further) content of the <Person> element, just as the
<Biography> element in the Mr X case.

I start to think that's impossible. Am I right?


Your schema has to allow the Xinclude or some similar way of expressing
where the other information should come from. Or that information has to
be supplied via some supplemental file.

Some tool -- whether it's Xinclude in the parser, or a stylesheet, or a
hardcoded process -- has to recognize that and replace it with the content.

That's certainly possible, and can be approached in multiple ways. If
you insist on constraining it unreasonably, you can _make_ it impossible...

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 7 '06 #6

P: n/a
Wojtek wrote:
Hello,

how can I transparently insert one XML file into another? I am looking
for a method simmilar to the #include <file> known from the C language.


FAQ: http://xml.silmaril.ie/authors/includes/

///Peter
Apr 9 '06 #7

P: n/a
Great thanks to you all for your answers and hints :)

Peter Flynn wrote:
FAQ: http://xml.silmaril.ie/authors/includes/


Peter, at the beginning I wanted to avoid using DTD (it means: mixing
DTD and XML Schema) in my documents, but now I think, that this seems to
be the simplest and most suitable solution for me.

Thank you one more time,
greetings,
Wojtek
Apr 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.