我不确定为什么这不起作用。
I have an XmlNode in a known-format. It is:
<[setting-name]>
<dictionary>
<[block-of-xml-to-process]/>
<[block-of-xml-to-process]/>
<[block-of-xml-to-process]/>
</dictionary>
</[setting-name]>
I have a reference to the node in a variable called pattern. I want an iterable collection of nodes, each of which is represented by a [block-of-xml-to-process] above. The name and structure of the blocks is unknown at this point. [Setting-name] is known.
This seems pretty straightforward. I can think of a half-dozen XPATH expressions that should point to the blocks. I ve tried:
XmlNodeList kvpsList = pattern.SelectNodes(String.Format(@"/{0}/dictionary/*", _CollectionName));
XmlNodeList kvpsList = pattern.SelectNodes(String.Format(@"{0}/dictionary/*", _CollectionName));
XmlNodeList kvpsList = pattern.SelectNodes(@"//dictionary/*");
XmlNodeList kvpsList = pattern.SelectNodes(@"//dictionary");
但是,显然我缺乏对XPATH的基本理解或者某些.SelectNodes的特殊技巧,因为它们都没有稳定地发挥作用。
我做错了什么?