I have a LibreOffice Basic macros to write/ read XML files. I have ported them from VBA. So far everything seems to be working except for retrieving the text from XML elements. Here is the (simplified) Sub that creates an XML object, writes it to file and reads an XML file into an XML object:
Sub ExportImportXML
Dim oleService, oXMLexp as Object, oXMLimp as Object
Dim oRoot, oNode as Object
Dim HOME as String
oleService = createUnoService("com.sun.star.bridge.OleObjectFactory")
' Change this one:
HOME = "C:\tmp"
' Create an XML object to export
oXMLexp = oleService.createInstance("Msxml.DOMDocument")
With oXMLexp
.async = False
.validateOnParse = False
.resolveExternals = False
oRoot = .createElement("Root")
.appendChild(oRoot)
oNode = .createElement("ElementA")
oNode.Text = "Text of ElementA"
oRoot.appendChild(oNode)
MsgBox oNode.xml
'THIS DOESN'T WORK!
'MsgBox oNode.Text
oNode = .createElement("ElementB")
oNode.Text = "Text of ElementB"
oRoot.appendChild(oNode)
MsgBox .xml
.Save(HOME & "\test1.xml")
End With
' Create an XML object to import
oXMLimp = oleService.createInstance("Msxml.DOMDocument")
With oXMLimp
.Load(HOME & "\test1.xml")
MsgBox .xml
oNode = .DocumentElement.getElementsByTagName("ElementA").Item(0)
MsgBox oNode.xml
'THIS DOESN'T WORK!
'MsgBox oNode.Text
End With
End Sub
As you can see, I can write to a Node using .Text but I cannot read from it.
By the way, this works perfectly in VBA.
Any ideas why this is happening?
Thank you in advance!