Solved

Reading XML files by name in C#

Posted on 2007-04-03
3
258 Views
Last Modified: 2008-02-01
Is there a way in C# to read nodes of XML by the node name?  I want to be able to read the following:

http://www.markit.com/news/RCD_ABX_HE_INDEX.xml

I want to extract the <red></red> code for each item and then within the <currentsettlement> I want to get the <factor>.

Thakns
0
Comment
Question by:techhound
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
emce earned 300 total points
ID: 18843984
XPathDocument xpd   = new XPathDocument( RCD_ABX_HE_INDEX.xml );                                          
XPathNavigator xpn  = xpd.CreateNavigator();
XPathNodeIterator i = xpn.Select("//data/abcds/red");
if ( i.MoveNext() )
  red = i.Current.Value;
xpn.Select("//data/abcds/currentsettlement/factot");
if ( i.MoveNext() )
  factor = i.Current.Value;
0
 

Author Comment

by:techhound
ID: 18844079
Hi,

The red code is correct but the factor gives me the red code as well.  I did change the misspelling from your code segment to the correct spelling, i.e., factot => factor.

Thanks
0
 
LVL 5

Assisted Solution

by:mzalewski
mzalewski earned 200 total points
ID: 18847508
Not sure if this will help, but try this:

XPathDocument xpd   = new XPathDocument( RCD_ABX_HE_INDEX.xml );                                          
XPathNavigator xpn  = xpd.CreateNavigator();
XPathNodeIterator i = xpn.Select("//data/abcds/red");
if ( i.MoveNext() )
  red = i.Current.Value;
i = xpn.Select("//data/abcds/currentsettlement/factor");
if ( i.MoveNext() )
  factor = i.Current.Value;

I think emce might have forgotten to assign the returned XPathNodeIterator to 'i' (the second xpn.Select).
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question