【发布时间】:2015-08-09 03:45:35
【问题描述】:
我正在尝试加入基于相同元素的两个 XML,但我的代码没有返回任何内容。 var 结果为空。有人可以帮忙解决这个问题吗?非常感谢!
文件一:
<bookstore>
<book>
<bookID>100</bookID>
<name> The cat in the hat </name>
</book>
<book>
<bookID>90</bookID>
<name> another book </name>
</book>
<book>
<bookID>103</bookID>
<name> a new book </name>
</book>
</bookstore>
文件二
<bookstore>
<book>
<bookID>100</bookID>
<content> story </content>
</book>
<book>
<bookID>90</bookID>
<content> fiction </content>
</book>
<book>
<bookID>103</bookID>
<content> bio </content>
</book>
</bookstore>
我正在寻找的结果是这样的:
<result>
<bookInfo>
<bookID>103</bookID>
<name> a new book </name>
<content> bio </content>
<bookInfo>
</result>
我当前使用的(错误)代码是:
var reslut =
from a in fileone.Descendants("bookstore")
join b in filetwo.Descendants("bookstore")
on (string)fileone.Descendants("bookID").First() equals (string)filetwo.Descendants(""bookID"").First()
select new XElement("bookInfo", a, b);
【问题讨论】:
-
我也尝试比较 bookstore.Element("bookID") 但这也返回一个空文件