Solved

Reading XML files by name in C#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DHCP server 6 51
Export import database 4 45
SQL Login 17 41
designing in object programming 12 52
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.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

25 Experts available now in Live!

Get 1:1 Help Now