Solved

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

Posted on 2013-12-03
3
460 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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