Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取特定元素包含值的XML中的Decents 临时许可证 线 满满的 完全访问 满满的 增强子帐户 增强的用户帐户 满满的 完全访问 满满的 临时许可证 线 满满的 完全访问 满满的 增强子帐户 增强的用户帐户 满满的 完全访问 满满的_C#_Xml - Fatal编程技术网

C# 获取特定元素包含值的XML中的Decents 临时许可证 线 满满的 完全访问 满满的 增强子帐户 增强的用户帐户 满满的 完全访问 满满的 临时许可证 线 满满的 完全访问 满满的 增强子帐户 增强的用户帐户 满满的 完全访问 满满的

C# 获取特定元素包含值的XML中的Decents 临时许可证 线 满满的 完全访问 满满的 增强子帐户 增强的用户帐户 满满的 完全访问 满满的 临时许可证 线 满满的 完全访问 满满的 增强子帐户 增强的用户帐户 满满的 完全访问 满满的,c#,xml,C#,Xml,如果my BundleType=line,如何将功能列表读入到IEnumerable中使用XDocument可以轻松完成此操作 <?xml version="1.0" encoding="utf-8" ?> <Licenses> <License> <LicenseType>Temporary License</LicenseType> <BundleType>Line</BundleType>

如果my BundleType=line,如何将功能列表读入到IEnumerable中使用XDocument可以轻松完成此操作

<?xml version="1.0" encoding="utf-8" ?>
<Licenses>
  <License>
    <LicenseType>Temporary License</LicenseType>
    <BundleType>Line</BundleType>
    <Features>
      <Feature>
        <Value>Full</Value>
        <Status>Full Access</Status>
        <AccessLevel>Full</AccessLevel>
      </Feature>
      <Feature>
        <Name>EnhancedUserAccounts</Name>
        <LocalisedName>Enhanced User Accounts</LocalisedName>
        <Value>Full</Value>
        <Status>Full Access</Status>
        <AccessLevel>Full</AccessLevel>
      </Feature>
    </Features>
  </License>
  <License>
    <LicenseType>Temporary License</LicenseType>
    <BundleType>Line</BundleType>
    <Features>
      <Feature>
        <Value>Full</Value>
        <Status>Full Access</Status>
        <AccessLevel>Full</AccessLevel>
      </Feature>
      <Feature>
        <Name>EnhancedUserAccounts</Name>
        <LocalisedName>Enhanced User Accounts</LocalisedName>
        <Value>Full</Value>
        <Status>Full Access</Status>
        <AccessLevel>Full</AccessLevel>
      </Feature>
    </Features>
  </License>
</Licenses>

然后:

将获取从LicenseType派生的所有节点

要测试BundleType元素,可以执行以下操作:

xDocument.Descendants("LicenseType")
这将获得父级的
为“行”的所有功能

编辑:根据注释,获取所有功能:

nodes.Where(n=>n.Element("BundleType") == "Line").Decesendants("Features")

这将使
元素下的所有
节点根据我在您的帖子中更新的xml使用以下内容:

xDocument.Desecendants("Features")

我已经使用XDocument licenseFeatureDocument=XDocument.Load(文件路径)读取了该文件,但在读取后,我必须将该功能读入包含捆绑类型的Ienumerable中,如Line抱歉,但我不太明白您想说什么。您想要所有功能,其中
BundleType==Line
?临时许可证行CimCommsLegacy过时的Cimcomms设备完全完全访问完全增强DuserAccounts增强用户帐户完全访问完全现在我想要bundle type==lineTemporary License Line Full-Access Full-EnhancedUserAccounts增强型用户帐户Full-Full-Access Full是指您的xml包含任何命名空间,如
xmlns
?请共享您的完整xml bcoz您的xml节点受到干扰?您能告诉我
LicenseType
的父节点吗?
nodes.Where(n=>n.Element("BundleType") == "Line").Decesendants("Features")
xDocument.Desecendants("Features")
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication70
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);

            var results = doc.Descendants("License").Where(x => (string)x.Element("BundleType") == "Line")
                .Select(x => x.Descendants("Feature").ToList()).ToList();
        }
    }
}