Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

including xml file within an xml file

Status
Not open for further replies.

Jimbob1981

Programmer
Jun 12, 2003
4
GB
Hi im fairly new to xml, and was wondering wether it is posible to inlcude a single xml within another xml file.

This is needed because the main xml file will have a node that is repeated several times and it would save time and effort to just have one file, that is included several times.

Can anyone provide the required syntax?

Thanks in advance
 
Jimbob,

I've inherited some code which does the following:

a) Declares a namespace as a attribute to the main xml tag in your XML file as follows:

xmlns:x="
b) includes the XML from the external files (also in the XML file) as follows:

<x:include href=&quot;../resources/resources.xml#xpointer(/resourcelist)&quot; parse=&quot;xml&quot;/>


c) adds a template to prevent the list being output in its raw form within the xsl file as follows:

<xsl:template match=&quot;resourcelist&quot; />

Not sure if you need this final step yourself.

Hope this helps,

Cheers Andy
 
Thanks Andy,

After many hours yesterday i realised that its quite impossible/difficult to use xinclude server side (which is necessary) on our ASP server, due to Xincldue processing not being implmented in the XML infoset :(

BUT i hadnt tried it using pointers, would this rectify the problem, or would it still not work due to crappy IIS :( oh for an apache PHP & Cocoon server :'( one day... one day

Also if you know of any server side method of implementing xinclude on a asp server, as this would be very handy and i would buy you a cake

Cheers for the post.

Jimbob
 
>> due to crappy IIS

What does IIS have to do with this problem? [hammer]

If your parser is not supporting the XML standards you desire use a different parser.

-pete
 
Ok, Will do...

know of any XML parsers that work with IIS, thats not the msdn XML?

Cheers
 
You can use the document() function in combination with the node-set extension to include the other file:

Include the namespace extension in your top level namespace declaration:

<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot; xmlns:ms=&quot;urn:schemas-microsoft-com:xslt&quot;>

Put the xml file into a temporary node called &quot;newnode&quot;:

<xsl:variable name=&quot;newnode&quot;>
<xsl:copy-of select=&quot;document('yourfile.xml')&quot;/>
</xsl:variable>

Use the node-set extension to work with the tree:

For example:
<xsl:for-each select=&quot;ms:node-set($newnode)/*&quot;>

etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top