Considerations Using a Unique Namespace
In the root tag, the attribute xmlns stands for the XML namespace. This allows you to define namespaces for tag names so that collisions can be avoided and validation logic can be run.
If you do not give a prefix for an XML namespace, but instead define it with the tag (xmlns) followed by a colon (:) and then a unique namespace, for example,
xmlns:psftFor example, this sort of functionality allows you to have two nodes named "Transaction", but one can be referenced by a "psft" namespace and another not, allowing for two nodes with the same name to exist, but each containing different data.
<?xml version="1.0"?>
<root xmlns:psft="http://www.example.com">
<psft:Transaction>Value</psft:Transaction>
<Transaction>Another</Transaction>
</root>
Incorrect results can be returned when you have a namespace as in the above example, which belongs to the namespace defined in http://www.people.com. When the system tries to find the path of "root/Transaction", it may return multiple nodes when in fact the end user might only want to return one.
To avoid this, do one of the following:
-
Do not use FindNode. Use GetElementByTagName instead. This does not use XPath to resolve entries in the DOM. Instead, it works at a node by node basis, for example, by getting the root node, then getting the transactions node. This code may be a bit more complex to write, but you loose the richness of XPath.
-
Give every xmlns attribute a prefix. The system will use XPath correctly and find the node.