Preliminary: Tips & Tricks
aus eecoo wiki, der freien Wissensdatenbank
Java
- new features of Java 1.5: Java 1.5 release notes
- enhanced for loops: http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html
XML
About namespaces, local names and qualified names
What is a namespace? Why do I need namespaces?
A namespace simply is a string value associated to a node that qualifies its scope. This means that the nodes local name gets its own meaning in the context of a namespace. You need namespaces to separate different contexts of your xml document and to avoid naming conflicts.
The following example shows the use of namespaces:
<html>
<head>...</head>
<body>
...
<html xmlns="http://my.namespace.org/"/>
</body>
</html>
Having defined the html element in line 5 with a namespace declaration (xmlns attribute) prevents this element from conflicts with the documents root element html. The scope of these two elements is different, the first html element is unqualified and could be meant as a html pages' content. The second one is qualified with the http://my.namespace.org/ namespace which is individually defined by myself to mark this element as a part of my datastructure. It has nothing to do with a webpages' html root element in my context.
Do namespaces have to be URIs?
No. You can use any string for namespace names, but it is declared as best practice to use URIs because of their world wide uniqueness. Therefore it is quite reasonable to use URIs as namespaces to avoid naming conflicts.
What are the differences between namespaces, prefixes, local names and qualified names?
<prefix:localName xmlns:prefix="namespace"/>
Namespaces qualify the scope of an element's or attribute's in the document. Namespaces are unique in a document, consequently all elements declared with the same namespace belong to that namespace. Prefixes are placeholders for namespaces. They're used to shorten up writing elements or attributes. Prefixes are do not have to be unique in a document. They can be redeclared and associated with other namespaces, even hierachically inside (as ancestors) of an equally prefixed element. The following example demonstrates this issue:
<prefix:localName xmlns:prefix="namespace1"> <prefix:localName xmlns:prefix="namespace2"/> </prefix>
In this example both localName named elements have a different namespace, although they have the same prefixes. A nodes local name name is the unqualified name of an element or attribute, i.o.w. the name without any namespace or prefix part. The nodes qualified name is the local name together with a namespace prefix like prefix:element. Instead of comparing elements or attributes with their qualified names directly, well written parsers resolve the namespace (which is identically associated with the prefix) before comparing nodes.
