Yeasin Abedin
Yeasin Abedin

Reputation: 2463

Get child element by name using XElement

I have below xml string

<Folder>
        <name></name>
        <Placemark>
            <name></name>
            <description></description>
            <styleUrl></styleUrl>
            <MultiGeometry>
                <Point>
                    <coordinates></coordinates>
                </Point>
                <LineString>
                    <coordinates></coordinates>
                    <tesselate>1</tesselate>
                </LineString>
            </MultiGeometry>
        </Placemark>
</Folder>

Using XElement, is there any way to pull Point element from the xml string without having to traverse through it's parent node? (MultiGeometry)

Upvotes: 1

Views: 10801

Answers (1)

N_tro_P
N_tro_P

Reputation: 693

If the data is loaded into a valid XElement you can use Descendants

e.g.

var xElement = XElement.Load(path);
var points = xElement.Descendants("Point");
var point = points.FirstOrDefault();

Upvotes: 10

Related Questions