Hello all
I have written the following LO Basic code to write XML via SAX to a file:
Sub WriteXMLwithSAX()
Dim sFil As String
sFil = "/tmp/output.xml" ' Change this for your needs
Dim oSFA As Object
oSFA = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
If oSFA.exists(sFil) Then oSFA.kill(sFil)
Dim oStm As Object
oStm = oSFA.openFileWrite (sFil)
Dim oSax As Object
oSax = CreateUnoService ("com.sun.star.xml.sax.Writer")
oSax.setOutputStream (oStm)
oSax.startDocument()
oSax.startElement("TopElement", Null) ' Instead of Null I'd like to
' use an XAttributeList element
oSax.startElement("ChildElement", Null)
oSax.characters("ChildValue")
oSax.endElement("ChildElement")
oSax.endElement("TopElement")
oSax.endDocument()
oStm.closeOutput()
End Sub
This produces a very pretty result “/tmp/output.xml” as expected:
<?xml version="1.0" encoding="UTF-8"?>
<TopElement><ChildElement>ChildValue</ChildElement></TopElement>
However, I’d like to add attributes to the elements “TopElement” and “ChildElement” to obtain e.g. a result like this:
<?xml version="1.0" encoding="UTF-8"?>
<TopElement A="Val1"><ChildElement B="Val2">ChildValue</ChildElement></TopElement>
If I read the LO SDK API correctly, I therefore should use a “XAttributeList” instead of the “Null” that I use above for calls of “startElement()”. “XAttributeList” only has “get…” functions but no “set…” functions and that is why I don’t have any idea how to create a valid “XAttributeList” for the use with “startElement()”. Can someone give me a hint how to create a “XAttributeList”?
Thank you very much.