My goal is to find and replace the values for (id, name, status) within an XML Node in VB6 using MSXML2.DOMDocument. I am working with older code but I didnt expect it to be this difficult I can pull the exact node I need from within the xml with getElementsByTagName. I currently have setAttributes for each value but it is not changing the node within the XML.
Dim oDOMOffer As New MSXML2.DOMDocument
Dim oldPendingNode As IXMLDOMElement
Dim newActiveNode As IXMLDOMElement
Dim sXMLGroup As String
Dim strId As String
Dim strName As String
Dim strInactive As String
On Error GoTo ErrHandler
'---
TraceEntry m_sProgID, csFunction
TraceParams m_sProgID, csFunction, Array("sXMLOffer", "sXMLOrigOffer"), Array(sXMLOffer, sXMLOrigOffer)
'---
'---
TraceEntry m_sProgID, csFunction
TraceParams m_sProgID, csFunction, Array("sXMLOffer", "sXMLGroup"), Array(sXMLOffer, sXMLGroup)
'---
'Take what we can get...
sXMLGroup = sXMLOffer
' Create a new element.
strId = "1"
strName = "ACTIVE"
strInactive = "FALSE"
''''''''newActiveNode = "<" & "offerstatus id='1' name='ACTIVE' inactive='FALSE'" & ">"
If oDOMOffer.loadXML(sXMLOffer) = True Then
If Not oDOMOffer.getElementsByTagName("group").nextNode Is Nothing Then
sXMLGroup = oDOMOffer.getElementsByTagName("group").nextNode.XML
'sXMLGroup = oDOMOffer.getElementsByTagName("offerstatus").nextNode.XML
'oldPendingNode = sXMLGroup
'oDOMOffer = oDOMOffer.replaceChild(newActiveNode, oldPendingNode).XML
' For starting User Name.
Set newActiveNode = oDOMOffer.createElement("offerstatus")
' Create an attribute and set its value to that of the new.
newActiveNode.setAttribute "id", strId
newActiveNode.setAttribute "name", strName
newActiveNode.setAttribute "inactive", strInactive
oDOMOffer.documentElement.appendChild newActiveNode
'---
Trace m_sProgID, csFunction, "sXMLOfferstatus:" & sXMLGroup
'---
'---
'Trace m_sProgID, csFunction, "newActiveNode:" & newActiveNode
'---
sXMLGroup = oDOMOffer.getElementsByTagName("group").nextNode.XML
'---
Trace m_sProgID, csFunction, "NewsXMLGroup:" & sXMLGroup
'---
Else
'---
Trace m_sProgID, csFunction, "ERROR: <group> node not found in sXMLOffer document text"
'---
End If
End If
My expected results would be
<offerstatus id="1" name="ACTIVE" inactive="FALSE">
but instead the id, name and inactive is keeping the same values in the XML. The general structure is this
<groups>
<group>
<offerstatus/>
</group>
</groups>
if this helps any. Then I am able to access the node offerstatus
.