Solved

Rename attributes (with XMLDOM, ASP on VBSCRIPT)

Posted on 2004-09-13
3
1,204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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