-1

我有xml:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<UpdateMemberHireStatus xmlns="http://tempuri.org/">
  <member>
    <HireAvailability>
      <code>1</code>
      <name>פנוי</name>
    </HireAvailability>
    <HireRejectReason>
      <code>2</code>
      <name>wow</name>
    </HireRejectReason>
    <IdNumber>43504349</IdNumber>
    <note> </note>
  </member>
</UpdateMemberHireStatus>

我想使用 LINQ 访问 xml 中的所有节点。

这是我尝试过的:

XNamespace ns = "tempuri.org/";
IEnumerable<HireStatus> status = from r in doc.Descendants(ns + "UpdateMemberHireStatus")
                                              .Descendants(ns + "member") 
                                 select new HireStatus() { }; 
return status.ToList();
4

3 回答 3

0

使用后代

var xml = XDocument.Load(XMLStream);
var allEle = xml.Descendants("UpdateMemberHireStatus"); //you can do linq now. 
于 2012-12-10T06:50:14.703 回答
0

您也可以通过以下方式使用 XDocument:

        string xmlPath = "D://member.xml";
        XmlDocument doc = new XmlDocument();
        xdoc = XDocument.Load(xmlPath);
        doc.LoadXml(xdoc.ToString());
        var memberStatus= (from mem in xdoc.Descendants("member")
                               select mem);

        foreach (XElement element in memberStatuses.ToList())            
            IEnumerable<XNode> nodes = element.Nodes();
于 2012-12-10T09:39:20.597 回答
-1

var x = XElement.Load(XMLStream);

var all = x.DescendantNodes();

于 2012-12-10T08:54:50.163 回答