PDA

View Full Version : Can I include an XML file within another XML file?



John
05-10-2011, 08:25 AM
I have been looking far and wide for some tutorial on how to include external data, for example another XML or TXT file, within an XML file.

What I would like to do is to get the data in red from another file:


<?xml version='1.0' encoding='UTF-8'?>
<markers>
<marker name="whatever" lat="-27.927513" lng="153.194305" category="Travel Guides" />
<marker name="something else" lat="27.927513" lng="-153.194305" category="Accommodation" />
<mapstyle zoom="5" lat="-22" lng="147" />
<category name="Accommodation" initial="show" />
<category name="Activities" initial="hide" />
</markers>
So I tried the following main file (based on http://www.w3.org/TR/xinclude/#rel-extent (http://www.w3.org/TR/xinclude/#rel-extent%29:))

<?xml version='1.0' encoding='UTF-8'?>
<markers xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="marker.xml"/>
<mapstyle zoom="5" lat="-22" lng="147" />
<category name="Accommodation" initial="show" />
<category name="Activities" initial="hide" />
</markers>
together with the marker.xml file:


<?xml version='1.0'?>
<marker name="whatever" lat="-27.927513" lng="153.194305" category="Travel Guides" />
<marker name="something else" lat="27.927513" lng="-153.194305" category="Accommodation" />but I am obviously doing something wrong, since I cannot get it to work at all.
Any help greatly appreciated.

Tiggerito
05-11-2011, 12:32 AM
I would suspect this is down to if the system parsing the markers supports XInclude . Probably not.

John
05-11-2011, 02:01 AM
I would suspect this is down to if the system parsing the markers supports XInclude . Probably not.
Mmmm ... I thought it was the browser that would do that? The parser I guess is the JS script creating a Google map based on the XML file. So would that be the script on my page, or the Google map script?

Here is a link to the test page I am working on: http://wizz.travel/choice

weegillis
05-20-2011, 05:17 PM
Might there also be some restrictions on the Google Maps server towards calling includes from a different domain? Whose server is parsing the XML? Could you generate an XML document that incorporates the include at request time?

John
05-20-2011, 07:34 PM
The way I solved it (with some help from a friend) is rather than trying to include an XML file within an XML file, I created a PHP file that includes two or more XML files. That fixed my problems.
See it in action here, it is all working now: http://wizz.travel/australia/queensland/

danieljames123
06-16-2011, 08:18 AM
Yes, you can use parsed external entity to include extra xml fragment into your xml. The entire well-formed XML file can be included too, but without xml decl!