How can I address specific XML-Elements with C# when using namespaces?

Joketime

New Member
I have to import XML-documents into a SQL-DB via C#. The XML has several namespaces.I tried to address the specific elements I want wo import via XPath, but it broke due to the namespaces. Instead of\[code\]XmlDocument doc = new XmlDocument();doc = XDocument.Load(Filename);GENERATOR_INFO = doc.SelectSingleNode("ORDER/ORDER_HEADER/ORDER_INFO/GENERATOR_INFO").InnerText;\[/code\]I write something like this:\[code\]XmlDocument doc = new XmlDocument();doc = XDocument.Load(Filename);XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);nsmgr.AddNamespace("openTrans", "http://www.opentrans.org/XMLSchema/2.1");GENERATOR_INFO = doc.SelectSingleNode("//openTrans:GENERATOR_INFO", nsmgr).InnerText;\[/code\]thus shortening the "path" to the element I need the Value of.My question is: How can I address an element directly? In the XMl there are two elements called "ORDER_ID":\[code\]ORDER/ORDER_HEADER/ORDER_INFO/ORDER_ID\[/code\]and\[code\]ORDER/ORDER_HEADER/CUSTOMER_ORDER_REFERENCE/ORDER_INFO\[/code\]When using the syntax above I get only one element, with a loop/Linq I get both values but don't know, which one is which.Is there an option to address the elements by there unique XPath despite the namespace?regardsJens
 
Back
Top