Solved

Rename attributes (with XMLDOM, ASP on VBSCRIPT)

Posted on 2004-09-13
3
1,162 Views
Last Modified: 2008-01-09
        <POINT_X X_NAME="[PLATFORM NAME]" X_NAME2="[REGION]">
            <SET Y_NAME="JUN" VALUE="285"/>
            <SET Y_NAME="WW18" VALUE="32355"/>
            <SET Y_NAME="WW19" VALUE="210"/>
            <SET Y_NAME="WW20" VALUE="130"/>
            <SET Y_NAME="WW21" VALUE="5335"/>
            <SET Y_NAME="JUL" VALUE="58"/>
         </POINT_X>

I need to rename all the Y_NAME to NAME. How do I achieve this?  I found no functions to rename attirbutes.
0
Comment
Question by:calvinfoo
3 Comments
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 50 total points
Comment Utility
Try node.removeAttribute()

Another option for transforming an XML document is to create a xslt transformation stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:template match="*|@*|text()">
        <xsl:copy>
                <xsl:apply-templates select="*|@*|text()"/>
        </xsl:copy>
</xsl:template>

<xsl:template match="set">
  <SET NAME="{@Y_NAME}" VALUE='{@VALUE}'>
      <xsl:apply-templates />
  </SET>
</xsl:template>
</xsl:stylesheet>
0
 
LVL 1

Author Comment

by:calvinfoo
Comment Utility
I am very new to XMLDOM, and XML.  My current solution is as below in ASP XMLDOM.   Please advise if anything can be improved, thanks :-)

<%
function renameAttributes(objXMLDoc, strSelectNodes, strOldAttribute, strNewAttribute)
set tempXML = objXMLDoc.documentElement.selectNodes(strSelectNodes)
if tempXML.length > 0 then
      for each item in tempXML
            item.setattribute strNewAttribute, item.getAttribute(strOldAttribute)
            item.removeAttribute strOldAttribute
      next
end if
      set renameAttributes = objXMLDoc
end function
%>
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 50 total points
Comment Utility
There is no standard DOM method of renaming an attribute...you're right in that you have to create a new one, and remove the old one.

Make sure you're not using the "Microsoft.XMLDOM" progId...use MSXML 3 or 4 instead:

Set xmlDoc = Server.CreateObject("Msxml2.DomDocument")
or
Set xmlDoc = Server.CreateObject("Msxml2.DomDocument.4.0")

And, if objXMLDoc is global, you can use a sub for this, and you don't really need to set the function equal to objXMLDoc

Regards,
Mike Sharp
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now