SelectSingleNode 不返回任何内容 [英] SelectSingleNode returns nothing
问题描述
我正在测试 SelectSingleNode
函数以从 Visual Studio 中的 XMLNode 对象获取单个节点,如下所示:
I'm testing the SelectSingleNode
function to fetch a single node from an XMLNode object in Visual Studio as follows:
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nsmgr.AddNamespace(ndListItems.Prefix, ndListItems.NamespaceURI)
Dim dummy As XmlNode = ndListItems.SelectSingleNode("/listitems", nsmgr)
此时,我只是想获取根节点,我正在使用 prefix 和 namespaceURI 属性添加到 XmlNamespaceManager
.问题是,当我运行调试器时,虚拟变量没有被分配,即什么都没有.请注意,当我分析 Prefix 和 namespace 属性的值时,它们如下所示,Prefix="" 和 NamespaceURI="http://schemas.microsoft.com/sharepoint/soap"
At this point, I'm just trying to get the root node and I'm using the prefix and namespaceURI property to add to the XmlNamespaceManager
. Problem is that when I run the debugger the dummy variable is not being assigned, i.e it is Nothing. Just to note, when I analyze the values of the Prefix and namespace property they are as follows, Prefix="" and NamespaceURI="http://schemas.microsoft.com/sharepoint/soap"
更新:
尝试更改代码,但我的虚拟 XMLNode 仍未设置
Tried changing the code, but my dummy XMLNode is still not getting set
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nsmgr.AddNamespace(ndListItems.Prefix, ndListItems.NamespaceURI)
Dim dummy As XmlNode = ndListItems.SelectSingleNode("/" + ndListItems.Prefix + "listitems", nsmgr)
这是我想要获取的 XML 代码片段,我的最终目标是访问 z:row 节点的属性
Here is the XML code snippet of what I'm trying to get, my ultimate goal is to access the attributes of the z:row node
<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<rs:data ItemCount="1">
<z:row ows_Title="Newhire" ows_FirstName="Rick" ows_WorkPhone="954" ows_HomePhone="954" ows_Email="genny.maxwell@email.com" ows_UserID="Rick.Newhire" ows_MetaInfo="9;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="9" ows_owshiddenversion="1" ows_UniqueId="9;#{0F6251A9-D3B8-4B07-A5F8-23BAF5F2237E}" ows_FSObjType="9;#0" ows_Created="2010-08-18 15:56:40" ows_FileRef="9;#Lists/NewHires/9_.000" />
</rs:data>
</listitems>
推荐答案
在您的输入示例中,z:row
元素的 QName 元组是 ("#RowsetSchema","row","z").这意味着 z
前缀的命名空间 URI 是 #RowsetSchema
.
In your input sample the QName tuple for z:row
element is ("#RowsetSchema","row","z"). Meaning that the namespace URI for z
prefix is #RowsetSchema
.
如果我没有弄错你的 C# 代码,这个 ndListItems.Prefix
评估为 listitems
元素的前缀,它是 none 或 "".因此,当您说 "/" + ndListItems.Prefix + "listitems"
时,它会被评估为/listitems",它将被解释为没有命名空间的 listitems
.
If I'm not getting wrong your C# code, this ndListItems.Prefix
evaluate to listitems
element's prefix wich is none or "". So, when you say "/" + ndListItems.Prefix + "listitems"
, it gets evaluated to "/listitems" wich it will be interpreted as a listitems
under no namespace.
所以,我认为您需要:
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nsmgr.AddNamespace("soap", "http://schemas.microsoft.com/sharepoint/soap/")
nsmgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset")
nsmgr.AddNamespace("z", "#RowsetSchema")
Dim dummy As XmlNode = ndListItems.SelectSingleNode("/soap:listitems/rs:data/z:row", nsmgr)
编辑:我发帖后想到了.
这篇关于SelectSingleNode 不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!