How can I “include” one XML file into another XML file?

I have a XML schema like:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="MySchema"
  <xs:element name="MyDocument">
        <xs:element name="TextHeader" type="xs:string" minOccurs="0" />
        <xs:element name="TextBody" type="xs:string" minOccurs="0" />

A valid XML document according to this schema would be:

<?xml version="1.0" encoding="utf-8" ?>
<MyDocument xmlns="">
  <TextHeader>My header which is almost always the same...</TextHeader>
  <TextBody>My text body which is always different...</TextBody>

Question 1: Is there a way to "include" the TextHeader element from another file?

Like so:

File "Header.xml":

<?xml version="1.0" encoding="utf-8" ?>
<MyDocument xmlns="">
  <TextHeader>My Header which is almost always the same...</TextHeader>

File "CompleteDocument.xml":

<?xml version="1.0" encoding="utf-8" ?>
<MyDocument xmlns="">

  include "Header.xml" ???

  <TextBody>My text body which is always different...</TextBody>

Question 2: If it's possible at all, will the .NET XMLSerializer be able to parse and understand the document containing such an "include..."?

Thank you for help in advance!


No to both questions. You could code something (like how app.config allows sections to be imported, or how xslt handles includes/imports), but this is not inbuilt onto any XML spec and would not match the existing schema. You'd have to do everything yourself, basically.

If you really wanted to go this route, writing a custom XmlReader that recognised a specific element (in a specific xmlns) and silently merging at that point - would perhaps be the beat choice.

Need Your Help

Gibberish is returned when runnign fopen/file_get_contents with one server but not with another

php curl character-encoding fopen file-get-contents

I'm building a script to check whether sites are up or not by reading a given page's content and looking for a predefined string in it (if the site is down the string won't be found).