Aaginor
Aaginor

Reputation: 4782

Getting child element of XElement by name

I have an XML structur in an XElement instance and want to get a child element.

The structure looks like this:

<metadata created="2016-10-19T13:58:30.669Z" xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
  <artist-list count="27242" offset="0">
    <artist id="8019364f-e30b-477f-9e04-35d1a7d19eab" type="Person" ext:score="100">
    ...

and I want to get the Element 'artist-list' to get the attributes count and offset from it.

I tried it with

myXElement.Element("artist-list");

but it returns null.

Any idea how to get the instance of "artist-list" from my structure?

Thanks in advance,
Frank

Upvotes: 1

Views: 2851

Answers (1)

Chuck Savage
Chuck Savage

Reputation: 11945

Because the element is in a namespace, and you aren't referencing it. Try,

XNamespace ns = "http://musicbrainz.org/ns/mmd-2.0#";

myXElement.Element(ns + "artist-list");

Upvotes: 2

Related Questions