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

Simple xpath expression problem

I am trying to use a simple xpath expression, the code looks like this:

Dim xdoc As New System.Xml.XmlDocument
Dim xnode1 As System.Xml.XmlNode
Dim xlist As System.Xml.XmlNodeList

xdoc.LoadXml(Application("MenuXML"))

xlist = xdoc.DocumentElement.SelectNodes("//MenuItem[@User=1]")

For Each xnode1 In xlist
xnode1.ParentNode.RemoveChild(xnode1)
Next

the xml document looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<MenuRoot>
<Page ID="101">
<MenuData ImagesBaseURL="images/" xmlns="ASP.NET Menu MenuData Schema">
<MenuGroup>
<MenuItem Label="Home" ID="1" User="0"></MenuItem>
<MenuItem Label="Reports" User="1">
<MenuGroup ExpandOffsetY="1" ExpandOffsetX="-1">
<MenuItem Label="Department" ID="7" />
<MenuItem Label="Division" ID="8" />
</MenuGroup>
</MenuItem>
</MenuGroup>
</MenuData>
</Page>
</MenuRoot>

can anyone tell me what is wrong with my xpath expression that it is not
finding the MenuItem with User=1? More specifically, why it is that xlist
has no nodes in it. I surely appreciate any help.

Thank You in advance, (I will likely thank you again later, though as well!)

Kirk

Nov 11 '05 #1
2 2783
Kirk wrote:
I am trying to use a simple xpath expression, the code looks like this:

Dim xdoc As New System.Xml.XmlDocument
Dim xnode1 As System.Xml.XmlNode
Dim xlist As System.Xml.XmlNodeList

xdoc.LoadXml(Application("MenuXML"))
'Create an XmlNamespaceManager for resolving namespaces.
Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(xdoc.NameTable)
nsmgr.AddNamespace("foo", "ASP.NET Menu MenuData Schema")
xlist = xdoc.DocumentElement.SelectNodes("//MenuItem[@User=1]")

xlist = xdoc.DocumentElement.SelectNodes("//MenuItem[@User=1]", nsmgr)

Search "XPath and default namespace" in archives for detail explanation,
this is the faqest faq.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Ahhhhh!,

thank you Oleg. that was my problem!

Kirk

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
Kirk wrote:
I am trying to use a simple xpath expression, the code looks like this:

Dim xdoc As New System.Xml.XmlDocument
Dim xnode1 As System.Xml.XmlNode
Dim xlist As System.Xml.XmlNodeList

xdoc.LoadXml(Application("MenuXML"))


'Create an XmlNamespaceManager for resolving namespaces.
Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(xdoc.NameTable)
nsmgr.AddNamespace("foo", "ASP.NET Menu MenuData Schema")
xlist = xdoc.DocumentElement.SelectNodes("//MenuItem[@User=1]")

xlist = xdoc.DocumentElement.SelectNodes("//MenuItem[@User=1]", nsmgr)

Search "XPath and default namespace" in archives for detail explanation,
this is the faqest faq.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3

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

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
0
by: Anna | last post by:
Hi all. I hav eproblems constructing one XPath expression. Here is what I want to do: I want to choose all area tags that belong to a certain image map, having src of the image map. I don't want...
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
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...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
2
by: Werner Sammer | last post by:
I would like to load an XML document from say D:\mytask\mydoc.xml into a CSharp and to retrieve from the resulting XML node tree a certain node/element by specifing an XPath expression. Does...
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
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
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: 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
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
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,...

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.