how to Check if a XML child element exists with Linq to XML

Tarek Saied picture Tarek Saied · Aug 26, 2012 · Viewed 24.6k times · Source

How can I check if IncomingConfig element exists by use linq to xml?

<?xml version="1.0" encoding="utf-8"?>
<settings>
  <IncomingConfig>
    <ip>10.100.101.18</ip>
    <port>5060</port>
  </IncomingConfig>
  <Device>
    <username>tarek</username>
    <AgentName>tarek</AgentName>
    <password>ffff</password>
  </Device>
  <Device>
    <username>adf</username>
    <AgentName>adf</AgentName>
    <password>fadsf</password>
  </Device>
</settings>

Answer

L.B picture L.B · Aug 26, 2012
bool b = xdocument.Descendants("IncomingConfig").Any();