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 ???To: NULL Date: 4/9/2008 8:47:00 AM On 9 Abr, 09:21, pe...@code4cerveja.com wrote: > 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-instr= uction()"> > > =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),getT= ipo().c_str(),GetTi=ADpoNS(getTipo())); > > pDOMDoc->loadXML(bstrXMLString); > > for(MSXML2::IXMLDOMNodePtr node=3DpDOMDoc->documentElement->firstChild;nod= e!=3D0;node=3Dnode->nextSibling) { > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nodePtr->appendChild(node-= >cloneNode(_variant_t((bool)true))); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > pDOMDoc->loadXML(nodePtr->xml);- Ocultar texto citado - > > - Mostrar texto citado - with strings is easier string xmlteste=3Dteste; string::size_type loc =3D xmlteste.find(">",0); string tipo; tipo.append(" "); tipo.append("xmlns=3D"); tipo.append("'"); tipo.append(GetTipoNS(getTipo())); tipo.append("'"); xmlteste.insert(loc,tipo); | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
