Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 654
Tarek Saied Avatar asked Aug 26 '12 15:08

Tarek Saied


1 Answers

bool b = xdocument.Descendants("IncomingConfig").Any();
like image 52
L.B Avatar answered Oct 17 '22 06:10

L.B