3

I want to do something like:

stringBuilder.AppendLine("   globalVar." + reader.GetAttribute(i).Name + " = " + reader[i] + "; //add param ");

Where "reader.GetAttribute(i).Name" is the component that doesn't work. Is there an equivalent method to get the name of an attribute?

1

3 Answers 3

6

Use reader.MoveToAttribute(i), then you can use reader.Name and reader.Value.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks this did work eventually... I had to change some logic but it did.
3

Use Name and Value directly on reader - see sample from Reading Attributes below:

if (reader.HasAttributes) {
  Console.WriteLine("Attributes of <" + reader.Name + ">");
  while (reader.MoveToNextAttribute()) {
    Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
  }
  // Move the reader back to the element node.
  reader.MoveToElement();
}

1 Comment

The link for the sample has changed. learn.microsoft.com/en-us/dotnet/api/…
0

GetAttribute() returns the string value of the attribute. It doesn't have a "name" property. Try to move to the attribute and then get the "Name" property.

2 Comments

What do you mean 'move the attribute'? I know that GetAttribute() returns the string value of the attribute... I am asking if there is a way to get the 'ids' if you will of each attribute.
I see John has the answer above. Reader . move to attribute(i). Them reader. Name should do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.