Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Rename attributes (with XMLDOM, ASP on VBSCRIPT)

Posted on 2004-09-13
3
Medium Priority
?
1,234 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 100 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 100 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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