Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-03
3
Medium Priority
?
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 64

Accepted Solution

by:
Fernando Soto earned 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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