I'm completely stuck in retrieving a specific node from a responseXML object that I got back from the GetUserProfileByName
(SharePoint / SPServices). I need a specific PropertyData
node (in the example "FirstName") and then retrieve the value of the "FirstName". Retrieving the value is not a problem, retrieving the specific node is...
Below a part from the returned XML (for the sake of the example I stripped some properties):
...
<PropertyData>
<Name>UserProfile_GUID</Name>
<Values>
<ValueData>
<Value xmlns:q1="...">206b47c7-cfdc-...</Value>
</ValueData>
</Values>
</PropertyData>
<PropertyData>
<Name>FirstName</Name>
<Values>
<ValueData>
<Value xsi:type="xsd:string">Maarten</Value>
</ValueData>
</Values>
</PropertyData>
...
Since I know that I need the property FirstName
, I do not want to iterate through the entire set of PropertyData
nodes until I've the correct one (slow). In XPath I can select FirstName
just by saying:
//PropertyData[Name='FirstName']/Values/ValueData/Value
However, I cannot do that in the xData.responseXML
object. I tried the following filter, finds and other things (in all kinds of variations):
$(xData.responseXML).SPFilterNode("PropertyData").find("[Name*=FirstName]")
$(xData.responseXML).SPFilterNode("PropertyData").find("[Name*='FirstName']")
$(xData.responseXML).SPFilterNode("PropertyData").filter("[Name*=FirstName]")
$(xData.responseXML).SPFilterNode("PropertyData[Name='FirstName']")
I did many searches, but was not able to find an answer. There were many partial answer which a I all tried, but were not working. Any one a clue...
Thanks in advance! Maarten
@Maarten I'm not at my computer right now to test, but try this:
$(xData.responseXML).find("Name:contains('FirstName')").closest("PropertyData")
REVISION 1: Given your feedback that an additional element is returned (the phonetic field), here is a revised selector to only return the one containing the FirstName element:
$(xData.responseXML)
.find("Name:contains('FirstName')")
.not(":contains('SPS-PhoneticFirstName')")
.closest("PropertyData");
Paul