XDocument.Descendants cannot distinguish between Parent / Child Elements

I have a XML like this:

<?xml version="1.0" encoding="utf-8"?>
<Document>
    <Interface>
        <Sections xmlns="http://www.siemens.com/automation/Openness/SW/Interface/v4">
            <Section Name="Static">
                <Member Name="3bool1" Datatype="&quot;3bool&quot;" Remanence="NonRetain" Accessibility="Public">
                    <AttributeList>
                        <BooleanAttribute Name="ExternalAccessible" SystemDefined="true">true</BooleanAttribute>
                        <BooleanAttribute Name="ExternalVisible" SystemDefined="true">true</BooleanAttribute>
                        <BooleanAttribute Name="ExternalWritable" SystemDefined="true">true</BooleanAttribute>
                        <BooleanAttribute Name="SetPoint" SystemDefined="true">false</BooleanAttribute>
                    </AttributeList>
                    <Sections>
                        <Section Name="None">
                            <Member Name="bool1" Datatype="Bool" />
                            <Member Name="bool2" Datatype="Bool" />
                            <Member Name="bool3" Datatype="Bool" />
                        </Section>
                    </Sections>
                </Member>
                <Member Name="int7" Datatype="Int" Remanence="NonRetain" Accessibility="Public">
                    <AttributeList>
                        <BooleanAttribute Name="ExternalAccessible" SystemDefined="true">true</BooleanAttribute>
                        <BooleanAttribute Name="ExternalVisible" SystemDefined="true">true</BooleanAttribute>
                        <BooleanAttribute Name="ExternalWritable" SystemDefined="true">true</BooleanAttribute>
                        <BooleanAttribute Name="SetPoint" SystemDefined="true">true</BooleanAttribute>
                    </AttributeList>
                </Member>
            </Section>
        </Sections>
    </Interface>
 </Document>

With the following code I can take all the descendants "Member" elements of bool "Datatype":

XNamespace ns = "http://www.siemens.com/automation/Openness/SW/Interface/v4";

var memb = doc.Descendants(ns + "Member")
     .Select(f => f.Attribute("Datatype"))
     .Where(n => n.Value.Contains("Bool"))
     .ToList();

memb.ForEach(i => Console.WriteLine("{0}\t", i));

What I want to do is:

  1. Search if some "Member" elements have or not some "Member" child elements (composed data types);
  2. Extract all child elements of that specific parent element (in this case bool1, bool2, bool3)


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Network Error and Timeout on Authorize.net JS

Spring Elasticsearch Operations