私は、学校に通ったすべての友達をFacebookから見ようとしています。私はFQLを使用して、教育情報を持つすべての友人を含むxmlファイルを取得します。しかし、私はFQLを使って同じ学校に通った人だけを選ぶことはできません。そのため、LinqをXMLに使用して、私が望むユーザーだけを選択しようとしています。私はいくつかの方法を試しましたが、それらは私にとってはうまくいかないでしょう。ここで条件付きLinqからXMLを選択(ネストされた選択ステートメント)
は私のLINQクエリです:
XDocument doc = RemoveNamespace (XDocument.Load(url));
string[] search = {"Katho", "katho", "kortrijk" , "vhti"};
List<string> keys = new List<string>(search);
var user = (from usr in doc.Descendants("user")
select new fbUser
{
name = usr.Element("name").Value,
email = usr.Element("email").Value,
current_location = StringExtensions.checkNull(usr.Element("current_location").Value,""),
hometown_location = usr.Element("hometown_location").Value,
pic = StringExtensions.checkNull(usr.Element("pic_square").Value,"http://www.fox16.com/media/avatar/default.jpg"),
education_history = (from edu in usr.Descendants("education_info")
//where usr.Element("education_history").HasElements
where keys.Contains(edu.Element("name").Value)
select new Education
{
name = StringExtensions.checkNull(edu.Element("name"),""),
year = StringExtensions.checkNull(edu.Element("year"),""),
school_type = StringExtensions.checkNull(edu.Element("school_type"),""),
concentrations = from conc in edu.Descendants("concentrations")
where (edu.Element("concentrations").HasElements)
select new Concentration
{
name = StringExtensions.checkNull(conc.Element("concentration").Value, "")
}
})
}).Take(5)
;
EDIT:XMLはここで見つけることができますサンプル:sample XML
もう一つの問題があります。学校名は、fbUserオブジェクトの直接の属性ではありません。また、XMLでschoolnameファイルだけなので、ここで、ここで
<user><education_history><education_info><name>
見つけることができます私の声明されています
where usr.Element("education_history").Element("education_info").Element(name").value == "schoolname"
問題は、XMLでeducation_historyまたはeducation_infoノードが常に存在しないということです。
だから私もこの問題を回避する方法が必要です。..
この問題上の任意のヘルプは非常に高く評価されています。
私があなたを助けてくれることを願っています!
Grtz
Thxを:あなたはトラブルあなたの
where
ステートメントを構築している場合、あなたがselect
パーツを作成した後までだから、あなたはそれを延期することができます!私は完全にそれを発見していないが、私は今非常に近くなっていると思う。 – ThdK質問を編集しました。あなたがもう一度見に行く気があれば?あなたの助けは非常に高く評価されます! – ThdK
編集に基づいてコードサンプルの 'where'ステートメントを更新しました。 – Prutswonder