我已经加载XML到的XDocument,看起来是这样的:获取包含“:”的decendant节点?
<MyXML xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MyApp.Client.Main.GUI.Report">
<Wrapper xmlns:d2p1="http://schemas.datacontract.org/2004/07/MyApp.Business.Entity">
<d2p1:_MultipelAttributId>156</d2p1:_MultipelAttributId>
</Wrapper>
</MyXML>
现在我需要得到_MultipelAttributId的价值,但指出这时候:
XElement element = (from cml2 in doc.Descendants("d2p1:_MultipelAttributId") select cml2).FirstOrDefault();
我得到异常有关“ :“?
那么我该如何得到价值?
使用'XNamespace'。它必须在你的xml中声明。 –
XML不可更改,但我已更新它以更好地匹配真正的XML。我需要的是获得_MultipelAttributId – Banshee
这个XML是无效的,因为你使用的命名空间前缀'd2p1',但没有声明它。 –