Solved

Query an XML document to check for a particular value for a given element name

Posted on 2013-12-03
3
449 Views
Last Modified: 2013-12-05
I have the following XML document, where I need to check if there exists an property with name = FieldName  and the value is  MTD.

<XtraSerializer version="1.0">      
    <property name="Control" iskey="true" value="Control">
         <property name="Item38" isnull="true" iskey="true">
                  <property name="SortByConditions" iskey="true" value="0" />
                  <property name="Visible">false</property>
                  <property name="SerializedSortByField" isnull="true" />
                  <property name="Caption">MTD</property>
                  <property name="FieldName">MTD</property>
                  <property name="Area">RowArea</property>
                  <property name="Name">fieldMTD</property>
                  <property name="FilterValues" isnull="true" iskey="true">
                        <property name="DeferFilterString" />
                        <property name="ValuesCore" iskey="true" value="0" />
                        <property name="Values">~Xtra#Array0, </property>
                        <property name="ShowBlanks">true</property>
                        <property name="FilterType">Excluded</property>
            </property>
      </property>
      <property name="Item4" isnull="true" iskey="true">
                  <property name="SortByConditions" iskey="true" value="0" />
                  <property name="Visible">false</property>
                  <property name="SerializedSortByField" isnull="true" />
                  <property name="Caption">ID</property>
                  <property name="FieldName">ID</property>
                  <property name="Name">fieldID</property>
                  <property name="FilterValues" isnull="true" iskey="true">
                        <property name="DeferFilterString" />
                        <property name="ValuesCore" iskey="true" value="0" />
                        <property name="Values">~Xtra#Array0, </property>
                        <property name="ShowBlanks">true</property>
                        <property name="FilterType">Excluded</property>
            </property>
      </property>
</XtraSerializer>
0
Comment
Question by:countrymeister
3 Comments
 
LVL 9

Expert Comment

by:BlueYonder
ID: 39693093
You can use LINQ2XML.  Check out http://msdn.microsoft.com/en-us/library/bb308960.aspx
0
 
LVL 1

Author Comment

by:countrymeister
ID: 39693411
Blue Yonder, Can you provide a solution
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39694559
Hi countrymeister;

The following query will return a boolean True or False Depending on whether name attribute equals FieldName and the inner text is "MTD".

// Change the Load parameter to the file path to XML document
XDocument xdoc = XDocument.Load("C:/Working Directory/xtra.xml");

// The variable existTest returns True/Fasle                
var existTest = xdoc.Descendants("property").Any(p =>  p.Attribute("name").Value == "FieldName" && p.Value == "MTD");

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

803 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