我有一个 Xml,我想按名称获取单个元素。我尝试使用 SelectSingelNode 方法。这就是 MSDN 告诉你要做的:
https://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectsinglenode%28v=vs.110%29.aspx
目前我正在使用 XmlDocument 和 XmlNodeList 来读取 Xml。但这给了我整棵树。
string path = "xml_path.xml";
FileStream reader = new FileStream(path, FileMode.Open, FileAccess.Read);
XmlDocument xdoc = new XmlDocument();
xdoc.Load(reader);
XmlNodeList node = xdoc.GetElementsByName("name");
Run Code Online (Sandbox Code Playgroud)
我在 win-universal-app 中找不到 SelectSingeNode 方法。我正在使用 Visual Studio 2015。为什么他们删除了这个?还有另一种方法可以通过名称获取单个元素吗?