开发者

SelectSingleNode returns nothing

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)

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"

UPDATE:

Tried changing the code, but my dummy XMLNode is still not getting set

Dim nsmgr开发者_Go百科 As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
        nsmgr.AddNamespace(ndListItems.Prefix, ndListItems.NamespaceURI)
        Dim dummy As XmlNode = ndListItems.SelectSingleNode("/" + ndListItems.Prefix + "listitems", nsmgr)

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>


You obviously have problem adding namespaces to the namespace manager.

Also, your XPath expression will at best select the top element, however you want z:row.

One simple and not too-elegant way to avoid namespace processing is the following

Use:

SelectSingleNode("/*/*/*")

or

SelectSingleNode("/*/*[local-name()='data']/*[local-name()='row']")


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.

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.

So, I think you need:

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)

Edit: It came to me, after I had posted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜