HugoHiasl
asked on
Help needed XPath.
Hi,
I'm nearly getting crazy at the moment about a really simple problem.
I use the GetUserCollectionFromWeb() Soap request to get some user data from a sharepoint server. It is giving me back some xml data. This looks like:
I need now a list with all single user to get the data from it and write it to a table in the database.
I tried the following two options. Both are not returning a node:
Could please someone assist?
Thanks in advance
I'm nearly getting crazy at the moment about a really simple problem.
I use the GetUserCollectionFromWeb()
<GetUserCollectionFromWeb xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">
<Users>
<User ID="1" Sid="S-1-5-21-8395456415-1532298954-1801674531-29583" Name="Mustermann Michael" LoginName="mydom\mustermann" Email="Mustermann.Michael@mydom.com" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
<User ID="1073741823" Sid="S-1-0-0" Name="System Account" LoginName="SHAREPOINT\system" Email="" Notes="" IsSiteAdmin="False" IsDomainGroup="False" />
</Users>
</GetUserCollectionFromWeb>
I need now a list with all single user to get the data from it and write it to a table in the database.
I tried the following two options. Both are not returning a node:
XElement ndListItems = userGroupSoapClient.GetUserCollectionFromSite();
object test1 = ndListItems.Descendants("User").ToList();
List<XElement> test = ndListItems.XPathSelectElements("//User").ToList();
Could please someone assist?
Thanks in advance
Your Descendants call refers to "User" where I think you meant to refer to "Users" (plural).
ASKER
This does not change anything.
But I would have expected a list with 1 resultNode with 6 subnodes if I use "Users" and I would expect a list with 6 nodes if I use "User".
But both gives 0 entries back. Does it have probably to do with the xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/" entry ??
But I would have expected a list with 1 resultNode with 6 subnodes if I use "Users" and I would expect a list with 6 nodes if I use "User".
But both gives 0 entries back. Does it have probably to do with the xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/" entry ??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This did not work because the DefaultNamespace seems to be empty...
But there is a Property "Name" which has a Subproperty Namespace which returns a XNamespace.
With this it works.
Thanks for your input It pointed me to the right direction.
But there is a Property "Name" which has a Subproperty Namespace which returns a XNamespace.
With this it works.
Thanks for your input It pointed me to the right direction.
This did not work because the DefaultNamespace seems to be empty...Hmm... My test was to put your XML in a file and load it into an XElement with XElement.Load. Perhaps there is something different in the way the default namespace is handled between our two codes.
In any event, combining your method with my method, here is the promised code for your second example:
System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager(ndListItems.CreateReader().NameTable);
mgr.AddNamespace("xyz", ndListItems.Name.Namespace.NamespaceName);
List<XElement> test = ndListItems.XPathSelectElements("//xyz:User", mgr).ToList();