开发者

How to use LINQ to read XML that contains xincluded files?

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"/>  
</A>

File B.xml

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

C# code:

 XElement ro开发者_如何学Pythonot = 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜