[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1244
  • Last Modified:

Rename attributes (with XMLDOM, ASP on VBSCRIPT)

        <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
calvinfoo
Asked:
calvinfoo
2 Solutions
 
MogalManicCommented:
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
 
calvinfooAuthor Commented:
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
 
rdcproCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now