特定のノードの属性値に基づいて値を取得する必要があるLinqからXmlクエリがあります。アイテムのリストを取得しようとしていますが、ノードの1つに値を取得する方法が見つからないような属性があります。私は短いそれを維持するために2つの項目を表示しています属性に基づいて値を取得するLinqとXML
<codelist-items>
<codelist-item>
<code>1</code>
<name>
<narrative>Planned start</narrative>
<narrative xml:lang="fr">Début prévu</narrative>
</name>
<description>
<narrative>
The date on which the activity is planned to start, for example the date of the first planned disbursement or when physical activity starts.
</narrative>
</description>
</codelist-item>
<codelist-item>
<code>2</code>
<name>
<narrative>Actual start</narrative>
<narrative xml:lang="fr">Début réel</narrative>
</name>
<description>
<narrative>
The actual date the activity starts, for example the date of the first disbursement or when physical activity starts.
</narrative>
</description>
</codelist-item>
</codelist-items>
: は、ここにXMLです。
XElement xelement = XElement.Load(xmlFile);
var elements = from adt in xelement.Elements("codelist-items").Elements("codelist-item")
select new ActivityDateType
{
Code = (string)adt.Element("code"),
NameEng = (string)adt.Element("name").Element("narrative"),
NameFra = (string)adt.Element("name").Element("narrative[@xml:lang='fr']"),
Description = (string)adt.Element("description")
};
return elements;
誰でもNameFraの値を取得する方法を知っている:「:LANG = 『FR』 XML」属性とここに私のLINQクエリを試してみて、そこにある「名前/物語」から値を取得するのですか?
おかげ
ありがとうhar07、それは私が必要としたものです。 – devguy