Hi Tim,
Ah the web service...this gets a "bit" more complicated! <G> A web service
(as you have seen) will return different namespaces and obviously these
have to be incorporated in the "setProperty" line but also where to use
which one in the selectSingleNode call.
Let me give you an example of what I mean by this. In my web service, I
return the following namespaces:
dfs
tns
and a blank namespace!
The only way I was able to determine this was to set a break point in my
code (use the word: debugger
![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
and then execute the following line of code
in the Immediate window:
?objCustomersConn.selectSingleNode("//dfs:myFields").xml
I pasted this into Notepad and found my "Customers" table (which I had
specified as the table name when I filled my dataset in the web service
code) had a blank namespace. This appeared as follows in the XML I was
reviewing in Notepad:
<NewDataSet xmlns=\"\"><Customers diffgr:id=\"Customers1\"
msdata:rowOrder=\"0\">
As you can see, there is no namespace prefix here. So in order for me to
get the node I was looking for, my selectSingleNode line now reads as
follows:
var objFound =
objCustomersConn.selectSingleNode("//dfs:myFields/dfs:dataFields/tns:GetCust
omersResponse/tns:GetCustomersResult//Customers[CustomerID = '" +
objCustID.text + "']");
If you notice above, between tns:GetCustomersResult and Customers there are
2 slashes "/" - the second is for the empty namespace!
Unfortunately not knowing the XML that your web service returns I cannot
pinpoint the exact issue but with the information above, hopefully it will
help you isolate the problem.
For your reference, here is my entire code to test against my web service
secondary data source:
//Get a reference to the GetCustomers WS data connection
var objCustomersConn = XDocument.GetDOM("GetCustomers");
//Get a reference to the field on the form to enter the CustomerID
var objCustID =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtCustomerID");
//Set the SelectionNamespaces property of the GetCustomers data connection
to walk the DOM
objCustomersConn.setProperty("SelectionNamespaces",
'xmlns:dfs="
http://schemas.microsoft.com/office/infopath/2003/dataFormSoluti
on" ' +
'xmlns:d="
http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
' +
'xmlns:tns="
http://tempuri.org/NWTables/Service1"' );
//Attempt to locate a customer with the entered CustomerID
var objFound =
objCustomersConn.selectSingleNode("//dfs:myFields/dfs:dataFields/tns:GetCust
omersResponse/tns:GetCustomersResult//Customers[CustomerID = '" +
objCustID.text + "']");
//If an invalid CustomerID was entered, display an error
if(objFound == null)
{
XDocument.UI.Alert("Not Found!");
}
//If a valid CustomerID was entered, display the CompanyName
else
{
XDocument.UI.Alert(objFound.selectSingleNode("CompanyName").text);
}
//Clean up
objCustomersConn = null;
objCustID = null;
objFound = null;
I hope something here helps!
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights