Solved

Rename attributes (with XMLDOM, ASP on VBSCRIPT)

Posted on 2004-09-13
3
1,176 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
ID: 12051063
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
ID: 12051206
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
ID: 12058196
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now