<book> element, then you can move to that element's attributes. Think of
"ian" <nospam@devdex.com> wrote in message
news:u1ynpU4jFHA.476@TK2MSFTNGP14.phx.gbl...
> Hi, I posted this on the general c# newsgroup a while ago and didn't get
> a reply, so dug about and found you all here :)
>
> ------Original message----------
>
> I'm using VS2005 latest beta, playing around with XML. I wanted a
> solution to the question I've seen asked many times which is "How do I
> get the attribute's name?" The traditional answer is to use an
> XmlNodeReader, although I found a LocalName property on the attribute
> when using a DOM.
>
> Here's some code:
>
> XmlDocument doc =new XmlDocument();
> XmlNodeReader reader = null;
> XmlNode anode = null;
>
> doc.loadxml("<book genre='novel' ISBN='1-861003-78'
> publicationdate='1987'> </book>");
> Debug.WriteLine(doc.ChildNodes.Count);
>
>
> Debug.WriteLine(doc.DocumentElement.Attributes.Item(0).LocalName.ToStrin
> g() + " = " + doc.DocumentElement.Attributes.Item(0).Value.ToString());
> //*1
>
> anode = doc.DocumentElement;
>
> reader = new XmlNodeReader(anode);
> reader.MoveToAttribute(0); //*2
> Debug.WriteLine(reader.Name);
> Debug.WriteLine(reader.ReadContentAsString());
>
> In the above code, the line commented //*1 works and returns the name of
> the first attribute and the value. The code at //*2 fails on
> MoveToAttribute and if you look in reader, reader.AttributeCount is 0.
> I must be missing something fundamental.
>
> Thanks.
>
>
>
>
> *** Sent via Developersdex
http://www.developersdex.com ***