Using Xpath With Default Namespace in C#

First – you don’t need a navigator; SelectNodes / SelectSingleNode should suffice. You may, however, need a namespace-manager – for example: XmlElement el = …; //TODO XmlNamespaceManager nsmgr = new XmlNamespaceManager( el.OwnerDocument.NameTable); nsmgr.AddNamespace(“x”, el.OwnerDocument.DocumentElement.NamespaceURI); var nodes = el.SelectNodes(@”/x:outerelement/x:innerelement”, nsmgr);

What does “var FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript?

Your guess as to the intent of || {} is pretty close. This particular pattern when seen at the top of files is used to create a namespace, i.e. a named object under which functions and variables can be created without unduly polluting the global object. The reason why it’s used is so that if … Read more

XSLT with XML source that has a default namespace set to xmlns

You need to declare the namespace in your XSLT, and use it in XPath expressions. E.g.: <xsl:stylesheet … xmlns:my=”http://www.mysite.com”> <xsl:template match=”/my:MyRoot”> … </xsl:template> </xsl:stylesheet> Note that you must provide some prefix if you want to refer to elements from that namespace in XPath. While you can just do xmlns=”…” without the prefix, and it will … Read more

How do I declare a namespace in JavaScript?

I use the approach found on the Enterprise jQuery site: Here is their example showing how to declare private & public properties and functions. Everything is done as a self-executing anonymous function. (function( skillet, $, undefined ) { //Private Property var isHot = true; //Public Property skillet.ingredient = “Bacon Strips”; //Public Method skillet.fry = function() … Read more

What does if __name__ == "__main__": do?

Short Answer It’s boilerplate code that protects users from accidentally invoking the script when they didn’t intend to. Here are some common problems when the guard is omitted from a script: If you import the guardless script in another script (e.g. import my_script_without_a_name_eq_main_guard), then the second script will trigger the first to run at import … Read more