tags:

views:

117

answers:

1

I am currently using VS2008, C# 3.5, and LINQ to read an XML file. (call it A.xml) I want to include other XML files in A.xml with xinclude. My initial attempts have failed, and I've not found any existing info published on how these two work together.

I'm creating the root element of my query by calling XElement.Load() Is there some other way of creating the root element that will process the include statement?

Example:
File A.xml

<A>  
  <xi:include href="B.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/&gt;  
</A>

File B.xml

<B>  
  <TAG_B Name="foo">  
    <TAG_C attr="bar"/>
  </TAG_B>  
</B>

C# code:

 XElement root = XElement.Load(@"A.xml");
 var b = from TAG_B in root.Descendants("B")
         let name = (string)TAG_B.Attribute("Name")
         where name.Equals("foo")
         select TAG_B;

I was hoping that XElement.Load would include the contents of B.xml and produce the following:

<A> 
  <B>  
    <TAG_B Name="foo">  
      <TAG_C attr="bar"/>
    </TAG_B>  
  </B>
</A>

Unfortunately, the include element is not processed, so there are no TAG_B elements in the enumarable.

+1  A: 

LINQ and the .Net framework do not support XInclude. There is a free project at SourceForge that implements XInclude for .Net, but I don't think it supports LINQ.

Dour High Arch