How do we access attributes using “XmlReader”

Q

How do we access attributes using “XmlReader”?

✍: Guest

A

Below snippets shows the way to access attributes. First in order to check whether there any attributes present in the current node you can use “HasAttributes” function and use the “MoveToNextAttribute” method to move forward in attribute. In case you want to move to the next element use “MoveToElement()”.

if (reader.HasAttributes)
{
while(reader.MoveToNextAttribute())
{
// your logic goes here
string pdata = reader.Value
}
}
reader.MoveToElement();

2007-10-31, 6926👍, 0💬