-2

I want to open an XML file in XML Notepad 2007, and save it under different name, using command line either from a batch file or from a VB6 function. The purpose of this action is to get each XML element on its own line, what I need for further data processing. I have found out how to open the file in XML Notepad 2007, but cannot find any info on switches/parameters that would execute "SaveAs" of the file.

brasofilo
  • 25,496
  • 15
  • 91
  • 179
  • Welcome on StackOverflow. Do you have .NET installed? If so, please try this better approach: http://stackoverflow.com/a/2661793/480982 – Thomas Weller May 12 '14 at 16:33

1 Answers1

1

You can use MSXML to do this yourself in VB6. Here is a small demo:

screenshot

Option Explicit

Private Sub ManageUI()
    'Make UI changes based on the relationships of controls and their
    'current values.
    chkStandalone.Enabled = chkOmitXMLDeclaration.Value <> vbChecked
End Sub

Private Sub chkOmitXMLDeclaration_Click()
    ManageUI
End Sub

Private Sub cmdReformat_Click()
    Dim rdrCompact As MSXML2.SAXXMLReader
    Dim wrtFormatted As MSXML2.MXXMLWriter

    Set wrtFormatted = New MSXML2.MXXMLWriter
    With wrtFormatted
        .omitXMLDeclaration = chkOmitXMLDeclaration.Value = vbChecked
        .standalone = chkStandalone.Value = vbChecked
        .indent = chkIndent.Value = vbChecked
        .output = "" 'Tells MXXMLWriter we want Unicode String output.
        Set rdrCompact = New MSXML2.SAXXMLReader
        With rdrCompact
            Set .contentHandler = wrtFormatted
            Set .dtdHandler = wrtFormatted
            Set .errorHandler = wrtFormatted
            .putProperty "http://xml.org/sax/properties/lexical-handler", _
                         wrtFormatted
            .putProperty "http://xml.org/sax/properties/declaration-handler", _
                         wrtFormatted
            .parse txtOriginal.Text
        End With
        txtPrettied.Text = .output
    End With
End Sub

Private Sub Form_Load()
    ManageUI
End Sub
Bob77
  • 13,167
  • 1
  • 29
  • 37
  • Thanks, Bob, If I understand it correctly, your solution is great if the size of XML source allows for cut-and-paste into upper window; however, in my case I need a function where I can pass the reference for source and export filenames to be processed, because the XML files sizes I have are around 300MB. – user3629308 May 15 '14 at 00:07
  • Well that's because it is an example, not free finished code to order. Take a look at the MSXML documentation. There is no problem with having the reader parse an input file, and the writer write to an output stream (ADO.Stream works fine, can save to disk). If your output is too large for ADO.Stream you can use your own code that implements IStream to encode the output data and write it to disk. Or skip the writer and implement the ISAXContentHandler Interface in your own VB6 class to handle the SAX output events. – Bob77 May 15 '14 at 01:17
  • Bob, if you're interested to do some small (paid) programming work for me, send me an email at dubravko@barac.ca – user3629308 Feb 25 '16 at 01:07
  • Thanks, but I have enough contract work to keep me busy at the present time. Maybe someone else will take you up on this. – Bob77 Feb 27 '16 at 12:38
  • BTW: If you have an input file you can replace the `.parse` call by `.parseURL "somefile.xml"` (it accepts local file names as well as URLs). – Bob77 Feb 27 '16 at 12:44