0

Is there a possible way within C# to get the value of the <PropertyID> node only when <IsDisabled> is equal to 0?

If not, how would I be able to parse out the PropertyIDs that have an IsDisabled value of 0?

I've been beating myself up with this all day so any help would be appreciated.

I have attached an example snippet of my XML below. I have condensed it significantly and there are many with a value of 1 and many with 0.

<response>
  <code>200</code>
  <result>
    <PhysicalProperty>
      <Property>
        <PropertyID>325213</PropertyID>
        <MarketingName>XXXXX</MarketingName>
        <Type>Student</Type>
        <IsDisabled>1</IsDisabled>
        <IsFeaturedProperty>0</IsFeaturedProperty>
      </Property>
    </PhysicalProperty>
  </result>
</response>
Mitch
  • 62
  • 1
  • 9

1 Answers1

1

Yes, LINQ makes it pretty easy to do these types of queries against XML

var propertyIds = XDocument.Parse(myXmlString)
                           .Descendants("Property")
                           .Where(p => p.Element("IsDisabled").Value == "0")
                           .Select(p => p.Element("PropertyID").Value);
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
  • Ok. I kind of get it. In this context what does p mean in your code? – Mitch Feb 24 '17 at 20:12
  • `=>` denotes an anonymous method. The left side (the `p`) are the arguments going into the method, the right side is the method body. You can research `anonymous method` or `lambda` – Jonesopolis Feb 24 '17 at 20:13