![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have this XML ?xml version="1.0" encoding="utf-8"? PORMessage key="new" j:effectiveDate="2007-05-21" xmlns:j="http://www.xxx.com/xxxx/3.0.3" xmlns="http://www.xxx.com" ActivityID ID>12345</ID /ActivityID /PORMessage =================== END ===== Then my C# code is: xmlDoc.LoadXml(xmlMsg); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("j", "http://www.xxx.com/xxxx/3.0.3"); |
|
XmlNode porNode = xmlDoc.SelectSingleNode("//PORMessage", nsmgr); |
#3
| |||
| |||
|
|
Phil Hunt wrote: I have this XML ?xml version="1.0" encoding="utf-8"? PORMessage key="new" j:effectiveDate="2007-05-21" xmlns:j="http://www.xxx.com/xxxx/3.0.3" xmlns="http://www.xxx.com" ActivityID ID>12345</ID /ActivityID /PORMessage =================== END ===== Then my C# code is: xmlDoc.LoadXml(xmlMsg); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("j", "http://www.xxx.com/xxxx/3.0.3"); nsmgr.AddNamespace("df", "http://www.xxx.com/"); XmlNode porNode = xmlDoc.SelectSingleNode("//PORMessage", nsmgr); XmlNode porNode = xmlDoc.SelectSingleNode("//df:PORMessage", nsmgr); The default namespace declaration (xmlns="http://www.xxx.com/") means that the elements are in the namespace http://www.xxx.com/. With XPath 1.0 to select elements in a namespace you need to bind a prefix (e.g. df) to the namespace URI and use the prefix to qualify element names in your XPath expression. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |