cm****@yahoo.co m wrote:
is there an easy way to provide all elements in an xml-document of a namespace-prefix.
Example of source file :
<book>
<title>Alaska </title>
</book>
convert to :
<bk:book xmlns:bk="http://localhost/mybooks">
<bk:title>Alask a</bk:title>
</bk:book>
can this be done using XmlDocument or another class ?
It is certainly possible using DOM programming with XmlDocument, you
need to process all element nodes and recreate them in the right
namespace and replace the nodes as needed.
Another way to solve that task is an XSLT stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="prefix" select="'bk'" />
<xsl:param name="namespace URI" select="'http://localhost/mybooks'" />
<xsl:output method="xml" />
<xsl:template match="*">
<xsl:element name="{$prefix} :{local-name()}"
namespace="{$na mespaceURI}">
<xsl:apply-templates select="@* | node() " />
</xsl:element>
</xsl:template>
<xsl:template match="@* | / | processing-instruction() | comment() |
text()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
which can then be applied using XslTransform.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/