473,396 Members | 1,971 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.

C# and XPath problem

Hi All

I am having trouble selecting a particular node within an XML document. I have given a sample of the XML below

<?xml version="1.0" encoding="ISO-8859-1"?>
<NETWORK>
<Objects>
<ObjectType>
<Dataset>gis</Dataset>
<Projection>CoordSys Earth Projection 8, 79, "mm", -2, 49, 0.9996012717, 400000000, -100000000</Projection>
<TypeName>distribution_point</TypeName>
<Object>
<Attributes>
<Attribute>
<AttribName>type</AttribName>
<AttribValue>I</AttribValue>
<AttribType>string</AttribType>
<AttribLength>4</AttribLength>
</Attribute>
</Attributes>
</Object>
</ObjectType>
</Objects>
</NETWORK>

I am trying to traverse to the <AttribName> Nodes with the following C# code

XPathDocument xpDoc = new XPathDocument(fName);
XPathNavigator xpNav = xpDoc.CreateNavigator();

// Compile a standard XPath expression
XPathExpression xpExpr;
//xpExpr = xpNav.Compile("/catalog/cd/price");
xpExpr = xpNav.Compile("/Network/Objects/ObjectType/Object");
XPathNodeIterator xpNodeIterator = xpNav.Select(xpExpr);

// Iterate on the NodeSet
try
{
while (xpNodeIterator.MoveNext())
{
XPathNavigator xpNav2 = xpNodeIterator.Current.Clone();
result += ("AttribLength: " + xpNav2.Value + "\n");
}
MessageBox.Show(result);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

However, when I execute the code, nothing is returned. I am fairly sure my XPath query is wrong but have tried everything.

I have tried the same code on simple XML examples and it works fine, but not with this XML.

Can anyone help?

Many thanks in advance
Anfield
Mar 23 '06 #1
1 3394
Sorry, I forgot to amend the expression I am using. It is not

xpExpr = xpNav.Compile("/Network/Objects/ObjectType/Object"); as stated but

xpExpr = xpNav.Compile("/Network/Objects/ObjectType/Object/Attributes/Attribute/AttribName");
Mar 23 '06 #2

Sign in to post your reply or Sign up for a free account.

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
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
1
by: Murtaza Tinwala | last post by:
Hi mates, I have the following problem in XSLT. I have following variables: ref-file = <path of XML document> eg "xmlDoc.xml" repeatpath = <a repeat path expressed in Xpath like /root/person >...
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a...
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...
3
by: muscha | last post by:
Hi All, I have this weird problem. I have an xml document and tried to do an XPath query to it. If I use the SelectSingleNode method it throws an exception but it works with SelectNodes method....
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 -...
3
by: abcd_68 | last post by:
Hi there, I'm using, for the first time, the JDK1.5 Xpath API. I need to find elements in a Hibernate-generated .hbm.xml file. These files come with a <!DOCTYPE header mentioning a remote URL....
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
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: 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...
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
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
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...
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.