Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: IXMLDOMDocumentPtr MSXML2::IXMLDOMNodePtr question ??? >Thread Next - Re: IXMLDOMDocumentPtr MSXML2::IXMLDOMNodePtr question ??? Re: IXMLDOMDocumentPtr MSXML2::IXMLDOMNodePtr question ???To: NULL Date: 4/9/2008 1:22:00 AM On 8 Abr, 18:40, Martin Honnen <mahotr...@yahoo.de> wrote: > pe...@code4cerveja.com wrote: > > i am trying to get the first element from XML and add it the xmlns > > namespace > > > how can i do this using =A0MSXML2 in C++ native ? > > The first element is the documentElement, there is a property for that > that you can access > <URL:http://msdn2.microsoft.com/en-us/library/ms759095(VS.85).aspx> > > However you can't change the namespace of nodes in a DOM document. If > you want to change the namespace you need to create new nodes in the > intended namespace. An XSLT stylesheet can do that easily and elegantly e.= g. > > <xsl:stylesheet > =A0 =A0xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" > =A0 =A0version=3D"1.0"> > > =A0 =A0<xsl:output method=3D"xml"/> > > =A0 =A0<xsl:param name=3D"ns" select=3D"'http://example.com/ns1'"/> > > =A0 =A0<xsl:template match=3D"*"> > =A0 =A0 =A0<xsl:element name=3D"{local-name()}" namespace=3D"{$ns}"> > =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"@* | node()"/> > =A0 =A0 =A0</xsl:element> > =A0 =A0</xsl:template> > > =A0 =A0<xsl:template match=3D"@* | text() | comment() | processing-instruc= tion()"> > =A0 =A0 =A0<xsl:copy/> > =A0 =A0</xsl:template> > > </xsl:stylesheet> > > -- > > =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML > =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/ we did it like this but this way its not the most efficient, can you make this better thanks MSXML2::IXMLDOMNodePtr nodePtr; nodePtr=3DpDOMDoc- >createNode(_variant_t((short)MSXML2::NODE_ELEMENT),getTipo().c_str(),GetTip= oNS(getTipo())); pDOMDoc->loadXML(bstrXMLString); for(MSXML2::IXMLDOMNodePtr node=3DpDOMDoc->documentElement- >firstChild;node!=3D0;node=3Dnode->nextSibling) { nodePtr->appendChild(node->cloneNode(_variant_t((bool)true))); } pDOMDoc->loadXML(nodePtr->xml); | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
