0
我有一個web服務,它返回xml數據作爲字符串。我正在嘗試將linq應用於由服務重新調用的xml字符串。Linq查詢不能在XML字符串上工作
可以說xml stirng有點像。
string str = "<root xmlns=\"http://tempuri.org/Count.xsd\"> <child> <subchild1>1</subchild1><subchild2>1</subchild2><subchild3>1</subchild3></child></root>";
下面是我使用的C#代碼。
XDocument xdoc = XDocument.Parse(str);
var item = xdoc.Element("root").Element("child").Element("subchild1");
但上述查詢總是返回null。
任何人都可以糾正我在代碼上面的和平有什麼問題。
該代碼看起來很好...你確定你實際上得到'空'嗎?這是你確切的XML嗎? –
我是根xmlns的一部分。更新了主要問題。 – Brainchild