I have the following method for parsing XMLElements:
DisplayMessages(XElement root)
{
var items = root.Descendants("Item");
foreach (var item in items)
{
var name = item.Element("Name");
....
}
}
In debug mode, I can see the root as XML as follows:
<ItemInfoList>
<ItemInfo>
<Item>
<a:Name>item 1</a:Name>
...
<Item>
...
and var is null (I expect to get "element 1"). I tried using "a: Name" but threw an exception ("character: cannot be used in name"). I'm not sure if I need to set the namespace in the root XElelement or not. All xml node as root must be in the same namespace.
I am new to XElement. In my codes, item.Element ("Name") will get its child values for the node "Name", right?
source
share