這是一個示例XML我只需要Nid的屬性IEnumerable的<XAttribute>被返回null,需要返回屬性值
<Server>
<Network Nid="43d5377-0dcd-40e6-b95c-8ee980b1e248">
<Client_Group id="20">963440d0-96dc-46a4-a54d-7251a65f585f</Client_Group>
<ClientID id="20">3fc8ffa1-c16b-4d7b-9e55-1e88dfe15277</ClientID>
<Server>
這是IEnumerable的爲XAttributes這樣我們就可以使用LINQ查詢一個屬性XML文檔,使用XElement訪問XML文件。由於某些原因,這返回Null,它需要返回屬性名稱「Nid」的屬性。
XElement main = XElement.Load(fi.FullName);
IEnumerable<XAttribute> successAttributes =
from attribute in main.Attributes()
where attribute.Name.LocalName == "Nid"
select attribute;
這是我的陣列
foreach (string attribute in successAttributes)
{
for (int i = 0; i < IntializedPorts.Count(); i++)
{
//running Intialization
IntializedNetworks[i] = attribute.ToString();
}
}
你的意思是'successAttributes的== null'? –
它的返回null導致一些不正確的查詢 – shawn
我剛剛添加了XElement的fi.Fullname是XML文檔的路徑 – shawn