473,395 Members | 1,530 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,395 software developers and data experts.

xpath query

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>

Oct 6 '08 #1
4 1782
Hi,
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
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 ...

Oct 7 '08 #2
Thank you, that did the trick.
"Alex Meleta" wrote:
Hi,
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
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 ...


Oct 7 '08 #3
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:
Hi,
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
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 ...


Oct 7 '08 #4
Nevermind that last question, I figured out what I was doing wrong.
"Alex Meleta" wrote:
Hi,
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
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 ...


Oct 7 '08 #5

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

Similar topics

1
by: Joshua Beall | last post by:
Hi All, I have a task that should be very simple but I'm running into trouble. All I want to do is query a document using XPath, and save the resulting XML in a string. Here's that I am trying...
6
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
8
by: Terry P | last post by:
Are there any tools (java classes, tag libraries) which can translate xpath statements into a SQL query? Given an xpath query which has a predicate that filters node values or attributes, I want...
3
by: gfrommer | last post by:
Hello Everyone, I'm writing a server in java, and I want the clients to pass me an XPath query. I want the XPath queries to be in a specific format though, I'm pretty sure it's valid but I want...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to construct an XPath query against an XML document, for a requirement that I have. Below is the XML fragment: <SUBMISSIONS> <SUBMISSION YEAR="2004"> <MONTH...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...
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...
0
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 projectplanning, coding, testing,...

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.