PDA

View Full Version : excel to xml (problem with listed elements)



dorina_
03-26-2008, 05:31 AM
Hi,

I have a problem with the following piece of code:

For t = 1 To j
Set XMLElement = XMLDoc.createElement("Correspondance")

Nodes = Split(sSgnMeasured, SIGNAL_DELIMITER)
sSignal = Nodes(k)
sVariabMat = Nodes(k + 1)

Call XMLElement.setAttribute("Signal", sSignal)
Call XMLElement.setAttribute("Var", sVar)
Call XMLParent.appendChild(XMLElement)
Next


which should return something like:
<Correspondance Signal="signal1" Var="signal1_M" />
<Correspondance Signal="signal2" Var="signal2_M" />

but it returns:
<Correspondance Signal="signal2" Var="signal2_M" />
<Correspondance Signal="signal2" Var="signal2_M" />
(it just puts the last signal in).


sSgnMeasured.......has the value of the item on which is clicked on, in the listbox.
I used some MsgBox-es to see what is stored in sSignal and in sVariabMat, and they store the right values, but when I look in the xml file, it looks wrong.
Please give me an idea of what I should change

Regards,
dori

xld
03-26-2008, 05:43 AM
Have you got a workbook and other files we can use?

dorina_
03-26-2008, 06:54 AM
sSgnMeasured = .List(i) & " - " & .List(i) & "_M"

sFile = ThisWorkbook.Path & "\default.xml"

With Worksheets("Main")
Set XMLDoc.documentElement = XMLDoc.createElement("Test")

Set XMLParent = XMLDoc.createElement("M_En")
Call XMLDoc.documentElement.appendChild(XMLParent)

If j > 0 Then
For t = 1 To j
Set XMLElement = XMLDoc.createElement("Correspondance")

Nodes = Split(sSgnMeasured, SIGNAL_DELIMITER)

Signal= Nodes(k)
sVariab= Nodes(k + 1)

Call XMLElement.setAttribute("Signal", Signal)
Call XMLElement.setAttribute("Var", sVariab)
Call XMLParent.appendChild(XMLElement)
Next
End If

Set XMLParent = XMLParent.parentNode
XMLDoc.Save sFile
End With