473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to include/insert one XML file into another?

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
7 4850
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
guys say if I include("anyfile.php") into a file. Is it possible for me to access the calling page from anyfile.php. Can I do something like this for instance:: if callingpage ==...
5
by: Bill | last post by:
I have perhaps not explained myself clearly, so I'll try it this way. In the code below, where it says "I'd like to include my navigation bar here" is the place I'd like to insert a navigation bar...
4
by: Mike Combe | last post by:
Hello All, Given..... <!--#include file="htm1.asp" --> Any ideas how to make the 'htm1.asp' a variable name? Say at one time we want to use 'htm1.asp' and another
3
by: Max Hazelhurst | last post by:
Hi there, Got an include file causing a timeout on the server when it's called on... The code has a loop in it that I suspect may be the cause... I can forward the entire inc file should it...
10
by: EnjoyNews | last post by:
I have a php site I have an include line called "include 'Cookie.php';" In this Cookie.php file I have these codes. <?php $conn = mysql_connect("$db", "$user", "$pass");...
9
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
6
by: Dmitri Shvetsov | last post by:
Hi All, Does somebody know how can I include an external file into my C# source file? I need to insert the same strings (about 5-10) into about 75 different files, probably I will need to...
5
by: Angel | last post by:
Is there some way to add a C-header file into a C# project? The problem is that this .h file contains several complex structures (over 20) that are used by some unmanaged code. These functions...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.