I'm trying to create an XML file based on some cell content in excel. Fairly new to VB, and this is the first thing I've tried writing as an excel macro. I was able to get a file that was structured properly using DOMDocument commands, and saving it once I had everything added. However, the encoding wasn't correct for my application- my output couldn't be imported into the program I need to get it into. This led me to MXXMLWriters. So, I have the following built from some examples I've seen here:
Sub WriteXML() Dim objDom As DOMDocument Set objDom = New DOMDocument objDom.validateOnParse = False Dim nodelist As IXMLDOMNodeList Dim wrt As New MXXMLWriter60 Dim cnth As IVBSAXContentHandler Dim atrs As New SAXAttributes60 Dim objNodeList Set cnth = wrt Set lexh = wrt 'Set the writer output to the xmlDoc object. wrt.output = objDom wrt.byteOrderMark = True wrt.indent = True wrt.Version = "1.0" wrt.Encoding = "UTF-8" wrt.standalone = "True" cnth.startDocument atrs.addAttribute "", "", "ExportOptions", "CDATA", "" atrs.addAttribute "", "", "ExportDate", "CDATA", "" cnth.startElement "", "", "Content", atrs cnth.endElement "", "", "Content" cnth.endDocument objDom.Save ("Result.xml") End Sub
This gives me the following output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
When i would expect to see:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Content ExportOptions="" ExportDate="" />I'm not sure what I missed, can anyone assist?