tags:

views:

332

answers:

5

I get this return value from Sharepoint... which I have just included the first part of the xml snippet...

<Result ID=\"1,New\" xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"&gt;
<ErrorCode>0x00000000</ErrorCode><ID /><z:row ows_ID=\"9\"

It populates a XmlNode node object.

How using xPath can I get the value of ows_id ?

My code so far...

XmlNode results = list.UpdateListItems("MySharePointList", batch);

Update

So far I have this : results.FirstChild.ChildNodes[2].Attributes["ows_ID"].Value

But I am not sure how reliable it is, can anyone improve on it?

A: 

When you start from root:

/Result/z:row/@ows_ID

also you can improve search if exists multiple Result:

/Result[@ID='1,New']/z:row/@ows_ID

Dewfy
A: 

The specific xpath calls depend on what library you use (e.g. libxml xpath implementation). But the generic xpath statement would be:

"//z:row[@ows_ID='9']"

This will select all z:row nodes with an attribute ows_ID of value 9. You can modify this query to match all z:row nodes or only those with a specific attribute.

For details look here: W3Schools XPath syntax

Shirkrin
I don't know the value of ows_id, thats what I want to retrieve. Any ideas on how to get that value as a string? I'm using C#
JL
A: 
<xsl:value-of select="Result/b:row/@ows_ID"/>

or

<xsl:value-of select="Result/b:row[@ows_ID = '9']"/>

Depending on what value you wanted

Tommy
A: 

You probably need to make sure the z namespace prefix is declared correctly - that's implementation dependent. Here's how you do it in Java's XPath implementation.

Then to select the value of the ows_ID attribute, you need to navigate to the element itself, then use @ows_ID to get the value.

Brabster
+2  A: 

I don't know if its necessarily an improvement, but it might be more readable, though more verbose:

/*[local-name() = 'Result']/*[local-name() = 'row']/@ows_ID

There is probably more to the fragment you posted so this XPath query might need a fixup when used against the actual xml result.

The function, local-name(), lets you ignore namespaces, which can be both a boon and a curse. :)

Zach Bonham