相关疑难解决方法(0)

XDocument.Descendants没有返回后代

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SetNationalList xmlns="http://www.lge.com/ddc">
      <nationalList>
        <portnumber>6000</portnumber>
        <slaveaddress>7000</slaveaddress>
        <flagzone>2</flagzone>
        <flagindivisual>5</flagindivisual>
        <flagdimming>3</flagdimming>
        <flagpattern>6</flagpattern>
        <flaggroup>9</flaggroup>
      </nationalList>
    </SetNationalList>
  </s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)

XDocument xdoc = XDocument.Parse(xml);
foreach (XElement element in xdoc.Descendants("nationalList"))
{
   MessageBox.Show(element.ToString());
}
Run Code Online (Sandbox Code Playgroud)

我想遍历每个节点,nationalList但它不适合我,它foreach完全跳过循环.我在这做错了什么?

.net c# xml linq-to-xml

36
推荐指数
2
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

linq-to-xml ×1

xml ×1