Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Parsing an XML Configuration file

Parsing an XML Configuration file

Parsing an XML Configuration file

I have an XML file for email sending that I need to parse.
Normally, this would be pretty straight forward, except this particular file has several entries, with an "IsEnabled" tag....
So, how would I go about finding the first node that is enabled?

Here's (partially) what the file looks like:


<SmtpClientsConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
			<SmtpDomain />
			<SmtpDomain />

... as you can see, the first node has "IsEnabled" set to True, however it may not always be the first node.
So, I guess what I need to do is find the first block with "IsEnabled" set to True, then find the parent of that block, and get the configuration settings from that block.

I know... it should be simple... but I haven't done a lot of XML parsing, especially in C#.

Thanks in advance!

Just my 2รณ

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."


RE: Parsing an XML Configuration file

Without Linq: https://msdn.microsoft.com/en-us/library/cc189056(...

With Linq: http://stackoverflow.com/questions/2594582/reading...
(I know this one isn't specifically about reading the document, but it shows you a code snippet that I think is one of the simplest approaches - using a custom object, which you then select all of the XML nodes into an enumeration of).

Stack overflow also has a large number of posts on this. Part of what you need to decide is what version of the .NET framework you're going to limit yourself to. The XML Linq stuff is quite useful, but requires higher levels of .NET the more of the features you make use of.

RE: Parsing an XML Configuration file

I would use an XPath for that, e.g.



"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close