I need to get the content of the POIssuedDate tag of the below XML using LINQ. Below is the code I wrote that I think should work.
EDIT : Just tried with XNamespace bat = @"x-commerceone:document:btsox:Batch.sox$1.0"; and XNamespace bat = @"urn:x-commerceone:document:btsox:Batch.sox$1.0"; both dont work.
The code throws an exception "Sequence contains no elements" which i expect if nothing matches given im using the First() method
Code
XDocument baseXML = XDocument.Load(Path.Combine(XMLFolder + @"\Provide.xml"));
XNamespace bat = @"xmlns:bat=""urn:x-commerceone:document:btsox:Batch.sox$1.0";
string date = baseXML.Descendants(bat + "Batch").Elements("PurchaseOrder").Elements("OrderHeader").Elements("POIssuedDate").First().Value;
XML
<?soxtype urn:x-commerceone:document:btsox:Batch.sox$1.0?>
<?import urn:x-commerceone:document:telcoapisox:ServiceRequestOrder.sox$1.0?>
<?import urn:x-commerceone:document:com:commerceone:CBL:CBL.sox$1.0?>
<?import urn:x-commerceone:document:btsox:DSL.sox$1.0?>
<bat:Batch BatchID="B-15-6-2001-4" NoOfEntries="3" xmlns="urn:x-commerceone:document:com:commerceone:CBL:CBL.sox$1.0" xmlns:bat="urn:x-commerceone:document:btsox:Batch.sox$1.0" xmlns:sro="urn:x-commerceone:document:telcoapisox:ServiceRequestOrder.sox$1.0" xmlns:dsl="urn:x-commerceone:document:btsox:DSL.sox$1.0">
<PurchaseOrder>
<OrderHeader>
<POIssuedDate>20010615T15:12:03</POIssuedDate>
..SNIP
</OrderHeader>
</PurchaseOrder>
</bat:Batch>