Alter the attributes content

Discussion in 'XML' started by Kasp, Oct 16, 2003.

  1. Kasp

    Kasp Guest

    Hi,
    Here is my problem....
    I have an XML with many "HierarchyMembe" node. I have to check the
    attributes called "PageKey" & "MemberName" for single quotes and replace
    their occurance with 2 single quotes. Here is my VB code that uses MSXML:

    Set hierarchyMemberList = xmlDocument.selectNodes("//HierarchyMember")
    For Each hierarchyMemberNode In hierarchyMemberList
    strPageKey =
    hierarchyMemberNode.Attributes.getNamedItem("PageKey").nodeValue
    strMembername =
    hierarchyMemberNode.Attributes.getNamedItem("MemberName").nodeValue

    If strPageKey = "" Then
    strPageKey = "null"
    Else
    strPageKey = Replace(strPageKey, "'", "''")
    End If

    If strMembername = "" Then
    strMembername = "null"
    Else
    strMembername = Replace(strMembername, "'", "''")
    End If

    'return safe attributes back to xml
    hierarchyMemberNode.Attributes.getNamedItem("PageKey").nodeValue =
    strPageKey
    hierarchyMemberNode.Attributes.getNamedItem("MemberName").nodeValue
    = strMembername
    Next
    xmlDocument.save("test.xml")

    My question is how can I change the attribute of this child. The last 2
    lines in the loop (getNamedItem = newValue) doesn't seem to work.

    Why is this happening and how can I change the existing attribute value to
    hold a new value?
    TIA.
    Kasp.
     
    Kasp, Oct 16, 2003
    #1
    1. Advertisements

  2. Kasp

    Martin Boehm Guest

    Work with a DomElement object (not a DOMNode) and use it's setAttribute
    method.

    Martin
     
    Martin Boehm, Oct 16, 2003
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.