473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XPath Request

SD
Hi,

How can i get all the nodes with attribute Name = "Publisher" or
Name="Administrator" using XPath query and C# for this xml doc?

<GetRoleCollectionFromUser
xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\">
<Roles>
<Role ID=\"1073741826\" Name=\"Reader\" Description=\"....\"
Type=\"2\" />
<Role ID=\"1073741827\" Name=\"Publisher\" Description=\"....\"
Type=\"3\" />
<Role ID=\"1073741828\" Name=\"Administrator\" Description=\"....\"
Type=\"1\" />
</Roles>
</GetRoleCollectionFromUser>

i tried:
*****
// XPATH query used
string sQuery = "//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrateur']";

// load the complete XML node and all its child nodes into an
// XML document
XmlDocument Document = new XmlDocument();
string strXmlNodeToQuery = "<GetRoleCollectionFromUser xmlns=....";
Document.LoadXml(strXmlNodeToQuery);

// namespaces used by SharePoint and
// choosen prefix
const string DirectoryNamespacePrefix = "d";
const string DirectoryNamespaceURI =
"http://schemas.microsoft.com/sharepoint/soap/directory/";

// now associate with the xmlns namespaces (part of all XML
// nodes returned from SharePoint), a namespace prefix that
// we then can use in the queries
XmlNamespaceManager NamespaceMngr = new
XmlNamespaceManager(Document.NameTable);
NamespaceMngr.AddNamespace(DirectoryNamespacePrefi x,
DirectoryNamespaceURI);

// run the XPath query and return the result nodes
XmlNodeList xnRolesList = Document.SelectNodes(sQuery , NamespaceMngr);

it didn't work, my "xnRolesList.Count" is always equal to 0.

Any ideas ?

Thanks

Best regards

SD

Aug 25 '06 #1
3 3300


SD wrote:

<GetRoleCollectionFromUser
xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\">
<Roles>
<Role ID=\"1073741826\" Name=\"Reader\" Description=\"....\"
Type=\"2\" />
<Role ID=\"1073741827\" Name=\"Publisher\" Description=\"....\"
Type=\"3\" />
<Role ID=\"1073741828\" Name=\"Administrator\" Description=\"....\"
Type=\"1\" />
</Roles>
</GetRoleCollectionFromUser>
string sQuery = "//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrateur']";
it didn't work, my "xnRolesList.Count" is always equal to 0.
With your sample and your XPath expression for me one node is found,
complete code:

string strXmlNodeToQuery = @"<GetRoleCollectionFromUser
xmlns=""http://schemas.microsoft.com/sharepoint/soap/directory/"">
<Roles>
<Role ID=""1073741826"" Name=""Reader"" Description=""....""
Type=""2"" />
<Role ID=""1073741827"" Name=""Publisher"" Description=""....""
Type=""3"" />
<Role ID=""1073741828"" Name=""Administrator"" Description=""....""
Type=""1"" />
</Roles>
</GetRoleCollectionFromUser>";

string sQuery =
"//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrateur']";

// load the complete XML node and all its child nodes into an
// XML document
XmlDocument Document = new XmlDocument();

Document.LoadXml(strXmlNodeToQuery);

// namespaces used by SharePoint and
// choosen prefix
const string DirectoryNamespacePrefix = "d";
const string DirectoryNamespaceURI =
"http://schemas.microsoft.com/sharepoint/soap/directory/";

// now associate with the xmlns namespaces (part of all XML
// nodes returned from SharePoint), a namespace prefix that
// we then can use in the queries
XmlNamespaceManager NamespaceMngr = new
XmlNamespaceManager(Document.NameTable);
NamespaceMngr.AddNamespace(DirectoryNamespacePrefi x,
DirectoryNamespaceURI);

// run the XPath query and return the result nodes
XmlNodeList xnRolesList = Document.SelectNodes(sQuery , NamespaceMngr);

Console.WriteLine("Founds {0} node(s).", xnRolesList.Count);

If you change the XPath expression to use the spelling "Administrator"
instead of "Administrateur" e.g.

string sQuery =
"//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrator']";

then two nodes are found.

So your C# code seems correct, only you have not shown us whether you
really load the XML sample. And the XPath when looking for the Name
attribute value has a different spelling for the attribute value than
the XML sample has.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '06 #2
SD
Sorry,
it was just a translation error:
my real code contained :
string sQuery = "//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrator']";
and my "xnRolesList.Count" is always equal to 0.

"Martin Honnen" <ma*******@yahoo.dea écrit dans le message de news:
Oi**************@TK2MSFTNGP03.phx.gbl...
>

SD wrote:

><GetRoleCollectionFromUser
xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\">
<Roles>
<Role ID=\"1073741826\" Name=\"Reader\" Description=\"....\"
Type=\"2\" />
<Role ID=\"1073741827\" Name=\"Publisher\" Description=\"....\"
Type=\"3\" />
<Role ID=\"1073741828\" Name=\"Administrator\" Description=\"....\"
Type=\"1\" />
</Roles>
</GetRoleCollectionFromUser>
> string sQuery = "//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrateur']";

> it didn't work, my "xnRolesList.Count" is always equal to 0.

With your sample and your XPath expression for me one node is found,
complete code:

string strXmlNodeToQuery = @"<GetRoleCollectionFromUser
xmlns=""http://schemas.microsoft.com/sharepoint/soap/directory/"">
<Roles>
<Role ID=""1073741826"" Name=""Reader"" Description=""....""
Type=""2"" />
<Role ID=""1073741827"" Name=""Publisher"" Description=""....""
Type=""3"" />
<Role ID=""1073741828"" Name=""Administrator"" Description=""....""
Type=""1"" />
</Roles>
</GetRoleCollectionFromUser>";

string sQuery =
"//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrateur']";

// load the complete XML node and all its child nodes into an
// XML document
XmlDocument Document = new XmlDocument();

Document.LoadXml(strXmlNodeToQuery);

// namespaces used by SharePoint and
// choosen prefix
const string DirectoryNamespacePrefix = "d";
const string DirectoryNamespaceURI =
"http://schemas.microsoft.com/sharepoint/soap/directory/";

// now associate with the xmlns namespaces (part of all XML
// nodes returned from SharePoint), a namespace prefix that
// we then can use in the queries
XmlNamespaceManager NamespaceMngr = new
XmlNamespaceManager(Document.NameTable);
NamespaceMngr.AddNamespace(DirectoryNamespacePrefi x,
DirectoryNamespaceURI);

// run the XPath query and return the result nodes
XmlNodeList xnRolesList = Document.SelectNodes(sQuery ,
NamespaceMngr);

Console.WriteLine("Founds {0} node(s).", xnRolesList.Count);

If you change the XPath expression to use the spelling "Administrator"
instead of "Administrateur" e.g.

string sQuery =
"//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrator']";

then two nodes are found.

So your C# code seems correct, only you have not shown us whether you
really load the XML sample. And the XPath when looking for the Name
attribute value has a different spelling for the attribute value than the
XML sample has.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Aug 25 '06 #3


SD wrote:

my real code contained :
string sQuery = "//d:Role[attribute::Name='Publisher' or
attribute::Name='Administrator']";
and my "xnRolesList.Count" is always equal to 0.
I have posted complete code which gives 1 (or 2 if the XPath is
adapted). It does not help to post some snippets to a newsgroup claiming
it gives certain results and then later to say the real code is
different. Post minimal but complete real code.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: K.Strunk | last post by:
Hi! I have a problem signing a XML-document. I need to sign a subnode of a document. So I need to refer to this subnode from within my signature. But how can I do that with XPath? I tried the...
0
by: Thor W Hammer | last post by:
Is it possible to use dynamic xpath expressions with the <%#XPath("..")%> syntax and XmlDataSource? This is a couple of examples to illustrate what I think about: 1: <%#XPath("*")%> 2:...
2
by: xerj | last post by:
I've worked out how to retrieve a parameter from a query string in a url using Request.Querystring("whatever"). However, what I can't figure out is how to feed this into an Xpath expression. For...
14
by: Mat| | last post by:
Hello :-) I am learning XPath, and I am trying to get child nodes of a node whose names do *not* match a given string, e.g : <dummy> <example> <title>Example 1</title> <body>this is an...
3
by: 0to60 | last post by:
Please help! I'm using the following code to get an XML doc: string str = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=12345&city=addison"; System.Net.HttpWebRequest request =...
1
by: newToAjax | last post by:
I have created an ajax application which retrievs an xml file and fills in the tab fields on the form.The code works fine in IE while its does not in Mozilla. Can you please let me know if i have to...
2
by: Amar | last post by:
I have XML Data: <REQUEST> <PARAMETERS> <PPM Name="CCCS Filed Date" value="xxxx"></PPM> </PARAMETERS> <RECORD _FiledDate="12/15/2003"></RECORD> </REQUEST>
0
by: bruce | last post by:
valid point...!! here's the test python.. ugly as it is!! Lodge It New All About ? Paste #83093
1
by: bruce | last post by:
Hi. Got a test web page, that basically has two "<html" tags in it. Examining the page via Firefox/Dom Inspector, I can create a test xpath query "/html/body/form" which gets the target form for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.