Solved

Check if a given value exists in an XML file

Posted on 2008-10-23
2
477 Views
Last Modified: 2013-12-17
Hi all,
I have a string value, for example "000057"

I have an XML with different values:
<?xml version="1.0" encoding="utf-8" ?>
<klanten>
      <klant>000051</klant>
      <klant>000052</klant>
      <klant>000053</klant>
      <klant>000054</klant>
      <klant>000055</klant>
      <klant>000056</klant>
      <klant>000057</klant>
      <klant>000058</klant>
      <klant>000059</klant>
      <klant>000060</klant>
      <klant>000061</klant>
</klanten>

How can I determine if the given value is located in the XML, retruning true or false ?
0
Comment
Question by:JamesBrian
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 22784215
Hello JamesBrian,

System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument;
xDoc.Load("MyDoc.xml");
If (xDoc.SelectSingleNode("klanten[klant='000057']") != null) {
  //it exists }
else
 {//it doesn't}

Regards,

TimCottee
0
 

Author Closing Comment

by:JamesBrian
ID: 31509127
Quick and good !
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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