Connecting Tech Pros Worldwide Help | Site Map

xpath query

  #1  
Old October 6th, 2008, 10:15 PM
=?Utf-8?B?TTFpUw==?=
Guest
 
Posts: n/a
I’m trying to pull up a NodeList of all the Grant elements in the
AccessControlList element of the xml document displayed below. However I’m
not getting the list using the following code:

XmlDocument doc = new XmlDocument();
doc.LoadXml(“MyXml”);
XmlNodeList nodes =
doc.SelectNodes("/AccessControlPolicy/AccessControlList");

What am I missing?

Scott


My Xml:

<?xml version="1.0" encoding="UTF-8" ?>
<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>xxxxxxxxxxxxxxxxxxxx</ID>
<DisplayName>username</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="CanonicalUser">
<ID>xxxxxxxxxxxxxxxxxxxx</ID>
<DisplayName>username</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="Group">
<URI>http://acs.amazonaws.com/groups/s3/LogDelivery</URI>
</Grantee>
<Permission>WRITE</Permission>
</Grant>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="Group">
<URI>http://acs.amazonaws.com/groups/s3/LogDelivery</URI>
</Grantee>
<Permission>READ_ACP</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>

  #2  
Old October 7th, 2008, 01:05 AM
Alex Meleta
Guest
 
Posts: n/a

re: xpath query


Hi,
Quote:
What am I missing?
1. Defining XmlNamespaceManager
var xmlNM = new XmlNamespaceManager(doc.NameTable);
2. Matching your own default namespace with a certain prefix, e.g. 'def'
xmlNM.AddNamespace("def", @"http://s3.amazonaws.com/doc/2006-03-01/");
3. Using defined prefix in query (including Grant if needed)
doc.SelectNodes("/def:AccessControlPolicy/def:AccessControlList/def:Grant",
xmlNM);

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
Quote:
I’m trying to pull up a NodeList of all the Grant elements in the
AccessControlList element of the xml document displayed below.
However I’m not getting the list using the following code:
>
XmlDocument doc = new XmlDocument();
doc.LoadXml(“MyXml”);
XmlNodeList nodes =
doc.SelectNodes("/AccessControlPolicy/AccessControlList");
What am I missing?
>
Scott ...

  #3  
Old October 7th, 2008, 02:05 AM
=?Utf-8?B?TTFpUw==?=
Guest
 
Posts: n/a

re: xpath query


Thank you, that did the trick.


"Alex Meleta" wrote:
Quote:
Hi,
>
Quote:
What am I missing?
1. Defining XmlNamespaceManager
var xmlNM = new XmlNamespaceManager(doc.NameTable);
2. Matching your own default namespace with a certain prefix, e.g. 'def'
xmlNM.AddNamespace("def", @"http://s3.amazonaws.com/doc/2006-03-01/");
3. Using defined prefix in query (including Grant if needed)
doc.SelectNodes("/def:AccessControlPolicy/def:AccessControlList/def:Grant",
xmlNM);
>
Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
>
Quote:
I’m trying to pull up a NodeList of all the Grant elements in the
AccessControlList element of the xml document displayed below.
However I’m not getting the list using the following code:

XmlDocument doc = new XmlDocument();
doc.LoadXml(“MyXml”);
XmlNodeList nodes =
doc.SelectNodes("/AccessControlPolicy/AccessControlList");
What am I missing?

Scott ...
>
>
>
  #4  
Old October 7th, 2008, 07:05 AM
=?Utf-8?B?TTFpUw==?=
Guest
 
Posts: n/a

re: xpath query


Another question, how do I go about accessing the values of the attributes in
the Grant nodes? The attributes property of the individual nodes are empty.


"Alex Meleta" wrote:
Quote:
Hi,
>
Quote:
What am I missing?
1. Defining XmlNamespaceManager
var xmlNM = new XmlNamespaceManager(doc.NameTable);
2. Matching your own default namespace with a certain prefix, e.g. 'def'
xmlNM.AddNamespace("def", @"http://s3.amazonaws.com/doc/2006-03-01/");
3. Using defined prefix in query (including Grant if needed)
doc.SelectNodes("/def:AccessControlPolicy/def:AccessControlList/def:Grant",
xmlNM);
>
Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
>
Quote:
I’m trying to pull up a NodeList of all the Grant elements in the
AccessControlList element of the xml document displayed below.
However I’m not getting the list using the following code:

XmlDocument doc = new XmlDocument();
doc.LoadXml(“MyXml”);
XmlNodeList nodes =
doc.SelectNodes("/AccessControlPolicy/AccessControlList");
What am I missing?

Scott ...
>
>
>
  #5  
Old October 7th, 2008, 07:15 AM
=?Utf-8?B?TTFpUw==?=
Guest
 
Posts: n/a

re: xpath query


Nevermind that last question, I figured out what I was doing wrong.


"Alex Meleta" wrote:
Quote:
Hi,
>
Quote:
What am I missing?
1. Defining XmlNamespaceManager
var xmlNM = new XmlNamespaceManager(doc.NameTable);
2. Matching your own default namespace with a certain prefix, e.g. 'def'
xmlNM.AddNamespace("def", @"http://s3.amazonaws.com/doc/2006-03-01/");
3. Using defined prefix in query (including Grant if needed)
doc.SelectNodes("/def:AccessControlPolicy/def:AccessControlList/def:Grant",
xmlNM);
>
Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
>
Quote:
I’m trying to pull up a NodeList of all the Grant elements in the
AccessControlList element of the xml document displayed below.
However I’m not getting the list using the following code:

XmlDocument doc = new XmlDocument();
doc.LoadXml(“MyXml”);
XmlNodeList nodes =
doc.SelectNodes("/AccessControlPolicy/AccessControlList");
What am I missing?

Scott ...
>
>
>
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with XPath query =?Utf-8?B?RGlmZmlkZW50?= answers 2 March 5th, 2007 05:15 PM
Simple xpath query with default namespace Jason Mobarak answers 3 December 3rd, 2006 09:05 PM
how do i create subset and union in XPath Query IMS.Rushikesh@gmail.com answers 3 November 12th, 2005 05:10 AM
how do i create subset and union in XPath Query IMS.Rushikesh@gmail.com answers 3 October 28th, 2005 06:55 AM
xpath query query David Gordon answers 2 July 20th, 2005 09:39 AM