473,804 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath Request

SD
Hi,

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

<GetRoleCollect ionFromUser
xmlns=\"http://schemas.microso ft.com/sharepoint/soap/directory/\">
<Roles>
<Role ID=\"1073741826 \" Name=\"Reader\" Description=\". ...\"
Type=\"2\" />
<Role ID=\"1073741827 \" Name=\"Publishe r\" Description=\". ...\"
Type=\"3\" />
<Role ID=\"1073741828 \" Name=\"Administ rator\" Description=\". ...\"
Type=\"1\" />
</Roles>
</GetRoleCollecti onFromUser>

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

// load the complete XML node and all its child nodes into an
// XML document
XmlDocument Document = new XmlDocument();
string strXmlNodeToQue ry = "<GetRoleCollec tionFromUser xmlns=....";
Document.LoadXm l(strXmlNodeToQ uery);

// namespaces used by SharePoint and
// choosen prefix
const string DirectoryNamesp acePrefix = "d";
const string DirectoryNamesp aceURI =
"http://schemas.microso ft.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
XmlNamespaceMan ager NamespaceMngr = new
XmlNamespaceMan ager(Document.N ameTable);
NamespaceMngr.A ddNamespace(Dir ectoryNamespace Prefix,
DirectoryNamesp aceURI);

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

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

Any ideas ?

Thanks

Best regards

SD

Aug 25 '06 #1
3 3318


SD wrote:

<GetRoleCollect ionFromUser
xmlns=\"http://schemas.microso ft.com/sharepoint/soap/directory/\">
<Roles>
<Role ID=\"1073741826 \" Name=\"Reader\" Description=\". ...\"
Type=\"2\" />
<Role ID=\"1073741827 \" Name=\"Publishe r\" Description=\". ...\"
Type=\"3\" />
<Role ID=\"1073741828 \" Name=\"Administ rator\" Description=\". ...\"
Type=\"1\" />
</Roles>
</GetRoleCollecti onFromUser>
string sQuery = "//d:Role[attribute::Name ='Publisher' or
attribute::Name ='Administrateu r']";
it didn't work, my "xnRolesList.Co unt" is always equal to 0.
With your sample and your XPath expression for me one node is found,
complete code:

string strXmlNodeToQue ry = @"<GetRoleColle ctionFromUser
xmlns=""http://schemas.microso ft.com/sharepoint/soap/directory/"">
<Roles>
<Role ID=""1073741826 "" Name=""Reader"" Description="". ...""
Type=""2"" />
<Role ID=""1073741827 "" Name=""Publishe r"" Description="". ...""
Type=""3"" />
<Role ID=""1073741828 "" Name=""Administ rator"" Description="". ...""
Type=""1"" />
</Roles>
</GetRoleCollecti onFromUser>";

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

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

Document.LoadXm l(strXmlNodeToQ uery);

// namespaces used by SharePoint and
// choosen prefix
const string DirectoryNamesp acePrefix = "d";
const string DirectoryNamesp aceURI =
"http://schemas.microso ft.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
XmlNamespaceMan ager NamespaceMngr = new
XmlNamespaceMan ager(Document.N ameTable);
NamespaceMngr.A ddNamespace(Dir ectoryNamespace Prefix,
DirectoryNamesp aceURI);

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

Console.WriteLi ne("Founds {0} node(s).", xnRolesList.Cou nt);

If you change the XPath expression to use the spelling "Administra tor"
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.Co unt" is always equal to 0.

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

SD wrote:

><GetRoleCollec tionFromUser
xmlns=\"http ://schemas.microso ft.com/sharepoint/soap/directory/\">
<Roles>
<Role ID=\"1073741826 \" Name=\"Reader\" Description=\". ...\"
Type=\"2\" />
<Role ID=\"1073741827 \" Name=\"Publishe r\" Description=\". ...\"
Type=\"3\" />
<Role ID=\"1073741828 \" Name=\"Administ rator\" Description=\". ...\"
Type=\"1\" />
</Roles>
</GetRoleCollecti onFromUser>
> string sQuery = "//d:Role[attribute::Name ='Publisher' or
attribute::Nam e='Administrate ur']";

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

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

string strXmlNodeToQue ry = @"<GetRoleColle ctionFromUser
xmlns=""http://schemas.microso ft.com/sharepoint/soap/directory/"">
<Roles>
<Role ID=""1073741826 "" Name=""Reader"" Description="". ...""
Type=""2"" />
<Role ID=""1073741827 "" Name=""Publishe r"" Description="". ...""
Type=""3"" />
<Role ID=""1073741828 "" Name=""Administ rator"" Description="". ...""
Type=""1"" />
</Roles>
</GetRoleCollecti onFromUser>";

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

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

Document.LoadXm l(strXmlNodeToQ uery);

// namespaces used by SharePoint and
// choosen prefix
const string DirectoryNamesp acePrefix = "d";
const string DirectoryNamesp aceURI =
"http://schemas.microso ft.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
XmlNamespaceMan ager NamespaceMngr = new
XmlNamespaceMan ager(Document.N ameTable);
NamespaceMngr.A ddNamespace(Dir ectoryNamespace Prefix,
DirectoryNamesp aceURI);

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

Console.WriteLi ne("Founds {0} node(s).", xnRolesList.Cou nt);

If you change the XPath expression to use the spelling "Administra tor"
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.Co unt" 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
1636
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 following, but I couldn't verify it using an online-verifier (http://www.aleksey.com/xmlsec/xmldsig-verifier.html). Could anybody please help me with that reference? Thanx a lot!
0
1483
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: <%#XPath("*%>]")%>
2
1670
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 instance, say I have an Xpath as follows: food/fruit. How do I programmatically alter the 'typeoffruit' attribute using the querystring in the url (example whatever.aspx?fruit=banana via Request.Querystring or whatever command is needed to...
14
2013
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 example</body>
3
4141
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 = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(str); request.Credentials = System.Net.CredentialCache.DefaultCredentials;
1
2343
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 install some plugins to use XPATH? <html> <head> <title>SilverLine </title> <link rel="stylesheet" href="example.css" TYPE="text/css" MEDIA="screen"> <script type="text/javascript"> /* Optional: Temporarily hide the "tabber" class so it...
2
1775
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
1260
by: bruce | last post by:
valid point...!! here's the test python.. ugly as it is!! Lodge It New All About ? Paste #83093
1
2219
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 the test. The issue comes when I examine the page's source html. It looks like: <html> <body> </body>
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.