选择LINQ to XML的元素

时间:2011-04-08 07:28:28

标签: linq-to-xml

我有以下XML。

<logs version="1.3.1.1" xmlns="http://www.witsml.org/schemas/131">
    <log uidWell="001" uidWellbore="001" uid="0c43e8df-ed63-41e4-878f-d1e5dd3b97d1">
        <startIndex uom="m">200.29</startIndex>
        <endIndex uom="m">209.73</endIndex>
        <logCurveInfo>
            <mnemonic>hkldAv1</mnemonic>
        </logCurveInfo>
        <logCurveInfo>
            <mnemonic>DEPTH</mnemonic>
        </logCurveInfo>
        <logCurveInfo>
            <mnemonic>wobAv1</mnemonic>
        </logCurveInfo>
        <logCurveInfo>
            <mnemonic>ropAv1</mnemonic>
        </logCurveInfo>
        <logData />
    </log>
</logs>

我想从XML中检索元素<logData>

我试过了,

XDocument xDoc = XDocument.Load(@"e:\data.xml");
XNamespace xmlns = "http://www.witsml.org/schemas/131";
XElement xlog = xDoc.Element(xmlns + "logData");

但它为xlog返回null。

1 个答案:

答案 0 :(得分:0)

您需要使用Descendants()深入了解层次结构,如下所示:

  var xlogs = xDoc.Descendants(xmlns + "logData");

这将为您提供所有logData的可枚举。