views:

370

answers:

1

I'm trying to parse my XML in C#.

Here's part of the file that is relevant:

<holder name="wnd_login" width="300" x="20" height="180">...</holder>

Here's the code that is supposed to read it:

while (reader.Read())
{
    if (reader.IsStartElement())
    {
        switch (reader.Name)
        {
            case "holder":
                Holder holder = new Holder(reader.GetAttribute("name"));
                ...
        }
    }
}

I read around that the common mistake was to forget a check to see if the element was a start element. I added it but the GetAttribute still returns null. Any idea?

A: 
tommieb75
The OP is using XmlReader not the DOM. Also I'm not really sure what's going on here in your example. The DOM doesn't require these kinds of gyrations to access attributes nor can I imagine how your catch block would ever be entered.
Josh Einstein