![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
i am receiving following xml from one party: #1 Request xmlns="http://somens.com" <SomeElement1>Element data</SomeElement1 <SomeElement1>Another element data</SomeElement1 /Request and before processing want to add prefix to the root element so the document should be: #2 ns0:Request xmlns:ns0="http://somens.com" <SomeElement1>Element data</SomeElement1 <SomeElement1>Another element data</SomeElement1 /ns0:Request |
utput method="xml"/>
#3
| |||
| |||
|
|
sashaxp wrote: i am receiving following xml from one party: #1 Request xmlns="http://somens.com" <SomeElement1>Element data</SomeElement1 <SomeElement1>Another element data</SomeElement1 /Request and before processing want to add prefix to the root element so the document should be: #2 ns0:Request xmlns:ns0="http://somens.com" <SomeElement1>Element data</SomeElement1 <SomeElement1>Another element data</SomeElement1 /ns0:Request So you are renaming the root element and the child elements as the default namespace is missing and that way the child elements are now in no namespace. Such tasks are solvable with an XSLT stylesheet: xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://somens.com" version="1.0" <xsl utput method="xml"/ <xsl:template match="/ns0:Request" <ns0:Request <xsl:apply-templates/ </ns0:Request </xsl:template <xsl:template match="*/*" <xsl:element name="{local-name()}" namespace="" <xsl:apply-templates/ </xsl:element </xsl:template /xsl:stylesheet You can apply XSLT tranformations using System.Xml.Xsl.XslCompiledTransform in .NET 2.0 and later and using System.Xml.Xsl.XslTransform in .NET 1.x. Doing that with the DOM is rather tedious as you would need to recreate each element with the proper prefix and namespace. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/- ๓หาูิุ รษิษาีลอูส ิลหำิ - - ๐ฯหมฺมิุ รษิษาีลอูส ิลหำิ - |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |