PC Review


Reply
Thread Tools Rate Thread

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

 
 
roto23@earthlink.net
Guest
Posts: n/a
 
      8th Jan 2007
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;

 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      8th Jan 2007
<(E-Mail Removed)> wrote:
> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
roto23@earthlink.net
Guest
Posts: n/a
 
      8th Jan 2007

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("DeathBenefitFactor").Value;
return strDBFactor;
]

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Attribute Diane Walker Microsoft Windows 2000 File System 3 6th Mar 2008 02:25 AM
Validation (XHTML 1.0 Transitional): Attribute 'height' is not a valid attribute of element 'table' perspolis Microsoft ASP .NET 1 23rd Jan 2007 07:57 AM
Validation (XHTML 1.0 Transitional): Attribute 'leftmargin' is not a valid attribute of element 'body'. anonymous Microsoft ASP .NET 1 2nd Aug 2006 09:05 AM
What is file attribute N? Chris Windows Vista General Discussion 0 27th Jun 2006 08:16 PM
Re: File attribute Jordon Microsoft Windows 2000 File System 0 15th Sep 2003 02:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:16 PM.