Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading XML files by name in C#

Posted on 2007-04-03
3
Medium Priority
?
260 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 1200 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 800 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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