how to ignore namespaces with XPath
You can use the local-name() XPath function. Instead of selecting a node like /path/to/x:somenode you can select all nodes and filter for the one with the correct local name: /path/to/*[local-name() = ‘somenode’]
You can use the local-name() XPath function. Instead of selecting a node like /path/to/x:somenode you can select all nodes and filter for the one with the correct local name: /path/to/*[local-name() = ‘somenode’]
The use operator is for giving aliases to names of classes, interfaces or other namespaces. Most use statements refer to a namespace or class that you’d like to shorten: use My\Full\Namespace; is equivalent to: use My\Full\Namespace as Namespace; // Namespace\Foo is now shorthand for My\Full\Namespace\Foo If the use operator is used with a class or … Read more
You should definitely NOT use using namespace in headers for precisely the reason you say, that it can unexpectedly change the meaning of code in any other files that include that header. There’s no way to undo a using namespace which is another reason it’s so dangerous. I typically just use grep or the like … Read more
Also, note that if you use the built-in templates to add classes to a folder, it will by default be put in a namespace that reflects the folder hierarchy. The classes will be easier to find and that alone should be reasons good enough. The rules we follow are: Project/assembly name is the same as … Read more
You’re basically referring to the section ยง7.3.1.1/2 from the C++03 Standard, The use of the static keyword is deprecated when declaring objects in a namespace scope; the unnamed-namespace provides a superior alternative. Note that this paragraph was already removed in C++11. static functions are per standard no longer deprecated! Nonetheless, unnamed namespace‘s are superior to … Read more
TL;DR: On Python 3.3 you don’t have to do anything, just don’t put any __init__.py in your namespace package directories and it will just work. On pre-3.3, choose the pkgutil.extend_path() solution over the pkg_resources.declare_namespace() one, because it’s future-proof and already compatible with implicit namespace packages. Python 3.3 introduces implicit namespace packages, see PEP 420. This … Read more
Globals in Python are global to a module, not across all modules. (Many people are confused by this, because in, say, C, a global is the same across all implementation files unless you explicitly make it static.) There are different ways to solve this, depending on your actual use case. Before even going down this … Read more
Instead of modifying the XML document itself, it’s best to parse it and then modify the tags in the result. This way you can handle multiple namespaces and namespace aliases: from io import StringIO # for Python 2 import from StringIO instead import xml.etree.ElementTree as ET # instead of ET.fromstring(xml) it = ET.iterparse(StringIO(xml)) for _, … Read more
You’re getting correct answers, let me just try re-wording: class Namespace::Class; Why do I have to do this? You have to do this because the term Namespace::Class is telling the compiler: …OK, compiler. Go find the namespace named Namespace, and within that refer to the class named Class. But the compiler doesn’t know what you’re … Read more
If Color is something that is specific to just Cars then that is the way you would limit its scope. If you are going to have another Color enum that other classes use then you might as well make it global (or at least outside Car). It makes no difference. If there is a global … Read more