0

I'm trying to get the value of attribute(memo) in an xml file using c#,also i want to display the value(wonderful day) in a textbox .Can anyone help?

<tree>
  <Product comment=" C# "  memo="Wonderful day" /> 
 </tree>
1

2 Answers 2

2

Take a look at XPath

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

Comments

1
var xml=@"<tree>
<Product comment="" C# ""  memo=""Wonderful day"" /> 
</tree>";

var doc = XDocument.Parse(xml);

var memo = doc.Document.Descendants("Product").Single().Attribute("memo").Value;

Output: Wonderful day

2 Comments

var xml =@"<tree><Product comment="" C# "" memo=""Wonderful day"" /> </tree>"; give error Data at the root level is invalid (xmlexception was unhandled)
@Karthik, Provided source code works perfectly, without any exception, tested.

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.