Solved

Reading XML files by name in C#

Posted on 2007-04-03
3
252 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Learn about cloud computing and its benefits for small business owners.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now