J
JY
Hi,
I'm using a query to find some elements in a XML document, based on an
attribute substring, but it throws a null exception in the code shown below:
static void Main(string[] args)
{
XElement root = XElement.Load("PurchaseOrders.xml");
IEnumerable<XElement> purchaseOrders =
from el in root.Elements("PurchaseOrder")
where
(from add in el.Descendants()
where
add.Attribute("MyAttribute").Value.Contains("ZXCV")
select add)
.Any()
select el;
foreach (XElement el in purchaseOrders)
Console.WriteLine((string)el.Attribute("PurchaseOrderNumber"));
}
It throws the exception in
add.Attribute("MyAttribute").Value.Contains("ZXCV")
Appreciate any help.
TIA,
SD
I'm using a query to find some elements in a XML document, based on an
attribute substring, but it throws a null exception in the code shown below:
static void Main(string[] args)
{
XElement root = XElement.Load("PurchaseOrders.xml");
IEnumerable<XElement> purchaseOrders =
from el in root.Elements("PurchaseOrder")
where
(from add in el.Descendants()
where
add.Attribute("MyAttribute").Value.Contains("ZXCV")
select add)
.Any()
select el;
foreach (XElement el in purchaseOrders)
Console.WriteLine((string)el.Attribute("PurchaseOrderNumber"));
}
It throws the exception in
add.Attribute("MyAttribute").Value.Contains("ZXCV")
Appreciate any help.
TIA,
SD