» An ultimate catalog of computer data
Forum posts for nsm
Select an XML node via XPath at an arbitrary depth
Having an XML document, I want to get the first node with a certain name, no matter in which nesting depth it is contained.
I tried several things without success:
var node1 = doc.SelectSingleNode(@'//Shortcut');
var node2 = doc.SelectSingleNode(@'/*/Shortcut');
var node3 = doc.SelectSingleNode(@'//*/Shortcut');
var node4 = doc.SelectSingleNode(@'*/Shortcut');
...
Each call results in a NULL node.
I think it should be some trivial XPath syntax. Can you help me?
(In case this matters: The XML document is an input file for a WiX project, so there could be some namespace issues involved?!?).
Edit
I also tried the following:
var nsm = new XmlNamespaceManager(doc.NameTable);
nsm.AddNamespace(string.Empty, @'http://schemas.microsoft.com/wix/2006/wi');
nsm.AddNamespace(@'ns', @'http://schemas.microsoft.com/wix/2006/wi');
together with:
var node1 = doc.SelectSingleNode(@'//Shortcut', nsm);
var node2 = doc.SelectSingleNode(@'/*/Shortcut', nsm);
var node3 = doc.SelectSingleNode(@'//*/Shortcut', nsm);
var node4 = doc.SelectSingleNode(@'*/Shortcut', nsm);
...
Leading to the same results.
Edit 2 - Solution
I found the solution:
var nsm = new XmlNamespaceManager(doc.NameTable);
nsm.AddNamespace(string.Empty, @'http://schemas.microsoft.com/wix/2006/wi');
nsm.AddNamespace(@'ns', @'http://schemas.microsoft.com/wix/2006/wi');
and then
var node1 = doc.SelectSingleNode(@'//ns:Shortcut', nsm);
This succeeded.
View complete forum thread with replies
Other posts related to nsm
See Related Forum Messages: Follow the Links Below to View Complete Thread
Using array notation instead of NSM on functions deeper then js.context.X
expressionengine: php error after install of nsm htaccess generator plugin: “The .htaccess p…
Parent child Relationship in mysql
Select an XML node via XPath at an arbitrary depth