Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Any easy to rename a Xml Element?

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 7/10/2007 1:44:00 PM

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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent