Alter the attributes content

K

Kasp

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.
 
M

Martin Boehm

[... VB Example snipped ...]

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.

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

Martin
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top