php5: ext/dom: unused namespace-definitions
[email protected] (Vivian Steller) Wed, 07 Apr 2004 15:47:02 +0200
| Newsgroups | php.xml.dev |
|---|---|
| Message-ID | <[email protected]> |
hello,
i have a short question about namespaces again.
if i have a document like:
<?xml version="1.0"?>
<prefix:element xmlns:prefix="namespaceUri"
xmlns:unusedPrefix="unusedNamespaceURI">
<!-- nothing -->
</prefix:element>
you can see that there is no element making use of the namespace
"unusedNamespaceURI".
passing this data to any doc->loadXML($data) method, the loadXML function
will remove the unused "xmlns:unusedPrefix" definition from the node. this
causes problems in my programm... is there a possibility to prevent the
function from removing unused namespaces?!
Think about the following scenario (my programm is about the same), where
the removement of the xmlns declarations causes into unexpected trouble:
in XSL document it is possible to match templates to elements on any
namespace, the following example demonstrates this fact:
...
<xsl:stylesheet version="1.0">
...
<xsl:template match="prefix:element"
xmlns:prefix="namespaceUri">
will be applied for prefix'ed elements
</xsl:template>
...
</xsl:stylesheet>
if you load this data into a document (as it is the 'normal' case on
transforming any data with DOM), the xmlns:prefix definition will be
removed as i mentioned on the top and thus the transformation could not be
executed. trying to use the match as an xpath expression you will get an
error like 'undefined namespace-prefix "prefix"'...
the error wouldn't appear if you define any element using the namespace:
...
<xsl:stylesheet version="1.0">
<prefix:namespaceOrWhatEver xmlns:prefix="namespaceUri"/>
...
<xsl:template match="prefix:element"
xmlns:prefix="namespaceUri">
will be applied for prefix'ed elements
</xsl:template>
...
</xsl:stylesheet>
I think this example shows a real case scenario - the possiblity to prevent
the load functions from "optimizing" the dom-tree like this would be
helpfull.
any comments are appreciated.
vivian