Link to home
Start Free TrialLog in
Avatar of Abirami Rajendran
Abirami RajendranFlag for United States of America

asked on

Linq query

I am trying to get elements from an XML that i created using XDocument.

 XDocument books = new XDocument(
                                    new XElement("Books",
                                new XElement("book",
                                    new XElement("name", "Book 1"),
                                    new XElement("author", "John Doe")),
                                new XElement("book",
                                    new XElement("name", "Book 2"),
                                    new XElement("author", "Jane Doe"))));

IEnumerable<XElement> elements = books.Element("books").Elements("book");


foreach (XElement element in elements)
              MessageBox.Show(element.ToString());


I get an error at the line IEnumerable<XElement> elements "Object reference not set to an instance of an object."

any help?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Abirami Rajendran

ASKER

Thanks
Not a problem, glad I was able to help.  ;=)