> It is because the namespaces are listed in the xml document that you have to set the property on the xml DOM. Note -- the DOM must know about the namespaces contained in the document or you will not be able to make a selection. That is why you must set the property.
>
[quoted text clipped - 31 lines]
> > IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
> > domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");
Hi, two things...
FIRST:
When you set the SelectionNamesapces property, you do it only once for all namespaces... like this:
XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:dsf="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
SECOND:
Maybe someone else can say for sure, but I'm not positive whether you can have two namespace prefixes that have the same namespace definitions... right now you have both DSF and DFS with the same definition...
The other thing about this is that I wonder if the DSF one should even be there. The DFS prefix is just an acronym for "dataFromSolution".
My guess is that you should be using the following call (using the DFS namespace):
iNodes = dcEmployees.SelectNodes("//dfs:Departments");

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
Hi Greg,
Thanks for all you assistance but I still cannot get my issue to work.
Basically, I have an InfoPath form connected to a receive data data connection called Departments on SharePoint
The script on the form is as follows:
function XDocument::OnLoad(eventObj)
{
Var dcDepartments;
Var iNodes;
//2 namespaces added as 2 are listed within xml
XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:dsf="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
dcDepartments = XDocument.GetDOM("Departments");
XDocument.UI.Alert(dcEmployees.xml);
//the xml that comes back is as attached below
iNodes = dcEmployees.SelectNodes("//dsf:Departments");
}
Everything works up until I do the iNodes query. I have no idea why it is still not parsing. I hope you can help
HI Greg,
Thanks, I sent you an e-mail directly to show you exactly what I have done
and hope that you may be able to assist. There is obviously something I am
doing wrong but don't know what. Hope you received the e-mail if not I can
re-send the small 3 or 4 line script
"Greg Collins [InfoPath MVP]" wrote:
> It is because the namespaces are listed in the xml document that you have to set the property on the xml DOM. Note -- the DOM must know about the namespaces contained in the document or you will not be able to make a selection. That is why you must set the property.
>
[quoted text clipped - 8 lines]
> > IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
> > domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");
Shem - 29 Nov 2004 13:53 GMT
Hi Greg,
I have tried this four ways 1) with dfs 2) with dsf 3) wth both and 4)
without both and every time I get the following error:
Referenece to undeclared namespace prefix dsf:
THe code in teh form I have is:
var dcEmployees;
var iNodes;
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:dsf="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
dcEmployees = XDocument.GetDOM("Employees");
XDocument.UI.Alert(dcEmployees.xml);
iNodes = dcEmployees.selectNodes("//dsf:Employees");
XDocument.UI.Alert(iNodes.Count);
And still getting nothing back for iNodes. DO you have access to sharepoint.
The reason I am asking is to see if you can get this to work on your
machine???
Regards,
Allan
> Hi, two things...
>
[quoted text clipped - 33 lines]
> > > IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
> > > domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");
Shem - 29 Nov 2004 14:31 GMT
Hi Greg,
SOLVED IT:
I set my object to GetDOM, then I use setProperty on new object not the
original XDocument.
So I have
dcEmployees = XDocument.GetDOM("Employees");
dcEmployees.setProperty("SelectionNamespaces",
'xmlns:dsf="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
> Hi, two things...
>
[quoted text clipped - 33 lines]
> > > IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
> > > domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");
Greg Collins [InfoPath MVP] - 29 Nov 2004 19:14 GMT
I'm glad you got it! Yes, in your previous post you are messing up the selection namespaces for the main dom... making it so you won't be able to make any more selections from that.
Keep up the good work!

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
Hi Greg,
SOLVED IT:
I set my object to GetDOM, then I use setProperty on new object not the
original XDocument.
So I have
dcEmployees = XDocument.GetDOM("Employees");
dcEmployees.setProperty("SelectionNamespaces",
'xmlns:dsf="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
"Greg Collins [InfoPath MVP]" wrote:
> Hi, two things...
>
[quoted text clipped - 24 lines]
> > > IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
> > > domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");
Shem - 06 Dec 2004 16:41 GMT
Hi Greg,
Instead of using a data connection I can ad a web reference in C#. How do I
access the service and run a method???
> I'm glad you got it! Yes, in your previous post you are messing up the selection namespaces for the main dom... making it so you won't be able to make any more selections from that.
>
[quoted text clipped - 42 lines]
> > > > IXMLDOMDocument2 domFoo = (IXMLDOMDocument2)thisXDocument.GetDOM("Foo");
> > > > domFoo.setProperty("SelectionNamespaces", "xmlns:abc=\"http://foo.bar.com/abc\"");