473,395 Members | 1,972 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.

I can't get the value of an attribute in an xml file

I am able to correctly XPath to the correct Node in the XML file,
however when I try to get the value of an attribute on that node, it
doenot work.

intX gets a value of 1 so I am sure the XPath query is correct but this
line retunrs an empty string...
strDBFactor = NodeIter.Current.GetAttribute("DeathBenefitFactor" , "");

here is the complete code..

string strDBFactor;
int intX;
strXmlQuery = "Root/DataPoint[@Age='40' and @RateClass='P' and
@Sex='F']";
docNav = new XPathDocument(strXmlFileNameAndPath);
nav = docNav.CreateNavigator();
NodeIter = nav.Select(strXmlQuery);
intX = NodeIter.Count;
strDBFactor = NodeIter.Current.GetAttribute("DeathBenefitFactor" , "");
return strDBFactor;

Jan 8 '07 #1
2 1242
<ro****@earthlink.netwrote:
I am able to correctly XPath to the correct Node in the XML file,
however when I try to get the value of an attribute on that node, it
doenot work.

intX gets a value of 1 so I am sure the XPath query is correct but this
line retunrs an empty string...
strDBFactor = NodeIter.Current.GetAttribute("DeathBenefitFactor" , "");

here is the complete code..

string strDBFactor;
int intX;
strXmlQuery = "Root/DataPoint[@Age='40' and @RateClass='P' and
@Sex='F']";
docNav = new XPathDocument(strXmlFileNameAndPath);
nav = docNav.CreateNavigator();
NodeIter = nav.Select(strXmlQuery);
intX = NodeIter.Count;
strDBFactor = NodeIter.Current.GetAttribute("DeathBenefitFactor" , "");
return strDBFactor;
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 8 '07 #2

Thanks for trying, but I got it working using this method..
private System.Xml.XmlDocument objXmlDoc;
private System.Xml.XmlNode objXmlNode;

public string SolveFordeathBenefit()
{
string strDBFactor;

objXmlDoc = new XmlDocument();
objXmlDoc.Load(strXmlFileNameAndPath);
strXmlQuery = "Root/DataPoint[@Age='40' and @RateClass='P' and
@Sex='F']";
objXmlNode = objXmlDoc.SelectSingleNode(strXmlQuery);
strDBFactor =
objXmlNode.Attributes.GetNamedItem("DeathBenefitFa ctor").Value;
return strDBFactor;
]

Jan 8 '07 #3

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

Similar topics

12
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA...
6
by: brian.ackermann | last post by:
Hi, Can someone tell me what I'm doing wrong here? It makes sense to me, but fails to actually execute the code. I can't find anything on google, but maybe my search criteria are off. ...
1
by: chiranjiv choudhary via .NET 247 | last post by:
Can we have CodeBehind file in another server or same machine but diffrent location or directory -------------------------------- From: chiranjiv choudhary ----------------------- Posted by a...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
2
by: charles-brewster | last post by:
I have progressed the copytext function test page a little since my original post here in the small hours this morning. It now opens a debugging window so I can try to figure out what it is or...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
1
by: otiose3 | last post by:
I've been ploughing through the archives here, but I can't seem to find a solution for my situation... Essentially, I want to run the JQuery script that is in the "value" attribute of my <option>...
0
by: Nathan Sokalski | last post by:
In the RadioButton and CheckBox controls, there is no Value attribute. The html <inputtag has a value attribute, which is used by both type="radio" and type="checkbox". The RadioButtonList and...
1
by: phpmel | last post by:
Hi guys, I wanted to set the value of a textbox to be the username of whoever is logged into my application. In the login page, a session variable username was set to be the username of whoever...
3
by: samit | last post by:
I have used an input control of type 'file' to upload image and i have checked the file extension( .jpeg or not) calling a javascript function . It is running well. but how can i set file object...
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
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 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.