XML : Excel XML import creates extra column called NULL for null values

I am using Excel 2010 / VBA / XML with the DOMDocument60 parser to produce reports of data in Oracle. I am having a problem with nulls. Oracle supports null-indicator="yes" in the xsql query to ensure that null fields are included in the returned recordset. If a field has a value the XML looks like this: <M_NOTCH>8</M_NOTCH> and if it is null it looks like this: <M_NOTCH NULL="TRUE"/>.

My code calls the web service to make the query:

Dim XML_HTTP As New MSXML2.XMLHTTP60: Call XML_HTTP.Open("POST", QUERY_URL, False): Call XML_HTTP.send

and retrieves the XML results:

Dim XML_OUTPUT As DOMDocument60: Set XML_OUTPUT = XML_HTTP.responseXML

It saves the file:

XML_OUTPUT.Save (FILE_PATH)

and then loads the spreadsheet from the saved file:

Call DestinationWorksheet.Parent.XmlImport(FILE_PATH, Nothing, True, DestinationWorksheet.Range("A1"))

which fills the Excel spreadsheet with the XML data.

If there is a null in the format like <M_NOTCH NULL="TRUE"/>, Excel thinks that this is two fields and creates one column for M_NOTCH (with no data for this row) and another column for NULL with a value of TRUE.

I have tried using the xsql setting null-indicator="no", and this eliminates the NULL column, but it has a different, unacceptable problem: The column order which is built dynamically so that if the first XML record represents an Oracle record with nulls the null fields are excluded from the XML and are only added to the Excel column list when records containing those fields are encountered in which case they are added to the end of the column list.

I have also tried replacing <M_NOTCH NULL="TRUE"/> with <M_NOTCH> </M_NOTCH> and that was successful.

Does anyone know how to either make Oracle use the syntax <M_NOTCH> </M_NOTCH> or get Excel to recognize <M_NOTCH NULL="TRUE"/> and not make an extra column?

No comments:

Post a Comment