IDE:VS 2010的WinForms,如何從XmlDocument中選擇具有命名空間的節點?
我有一個XML字符串
string xmlstr = "<string xmlns="http://example.com/proj1">True|Success</string>";
我想選擇<string>
節點,以獲得其InnerText
後續解析:
True|Success
使用以下代碼:
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xmlstr);
string message = xdoc.SelectSingleNode("string").InnerText; //Here getting null Execption error.
你能告訴我如何從xml中選擇此消息嗎?
您的XPath應該是'// string' –
這個問題經常被問到,很難從衆多可用的重複項中進行選擇。 – Tomalak
@Tomalak我不會說這是重複的。 – t3chb0t