Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Any easy to rename a Xml Element? [Thread Next] Re: Any easy to rename a Xml Element?To: NULL Date: 7/10/2007 10:43:00 AM
On Jul 10, 4:44 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> Carol wrote:
> > I got the following xml from my code:
> > <Template><a><b></b></a></Template>
>
> > I just want to replace the outside tag name to "Message"
> > <Message><a><b></b></a></Message>
>
> > I'm using VC and msxml2. Is there any easy way to set the name of an
> > xml element, just like the XmlElement.Name{get,set} in C#?
>
> You are wrong about C# and XmlElement, see
> <http://msdn2.microsoft.com/en-us/library/System.Xml.XmlElement.Name.aspx>
> there is only a getter for that property.
>
> The same holds for MSXML or other DOM implementations. So you need to
> create a new element and replace the old one with that e.g. (JScript syntax)
> var message = xmlDocument.createElement("Message");
> var replacedNode = xmlDocument.replaceChild(message,
> xmlDocument.documentElement);
> while (replacedNode.hasChildNodes()) {
> message.appendChild(replacedNode.firstChild);
> }
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
Thanks, I see. What I strongly believed turns out to be wrong... bad
memory.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
