WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

MSXML

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Using the DOM to Create XML

Keywords:  DOM XML

Somebody asked about using WB with XML files.

I personally prefer the MSPersist OLE driver, but not all XML fits the MS XML-Recordset standards.

The normal alternative would be low-level file i/o since XML is just ASCII with Attitude. But MS does provide the XMLDOM object, and I think version 1.0 comes with IE5 - otherwise MSXML 3.0 and the SDK an be downloaded from MSDN for free.

To the point, the script below illustrates using the DOM to create XML - might be useful to transfer LAFF databases to XML.


; ======= Winbatch: Using OLE with the XMLDOM Object   =================== ;
;  This was tested with MSXML 3.0. Use this to create or parse data        ;
;  saved to XML without using the Mircosoft RS.Save() ADO method -         ;
;  especially if you don't want or need Microsofts's schema info.          ;
;                                                                          ;
;  Stan Littlefield  ( stanl@btitelecom.net )    January 23, 2002          ;
; ======================================================================== ;


file   = Strcat( DirGet(),"testDom.xml" )       ; file to save as
oDOM   = ObjectOpen( "MSXML2.DOMDocument.3.0" ) ; open the Object
;oDOM   = ObjectOpen( "Microsoft.XMLDOM" )      ; an older 'default'


; build the root element
oRoot  = oDOM.CreateElement( "ROOT" )
oDOM.AppendChild( oRoot )

;build child elements
o1     = oDOM.CreateElement( "FirstChild" )
; add data to the child, normally this would be within a loop
; adding data each time
o1.Text = "Hello I am the first Child Element"
oRoot.AppendChild( o1 )


o1     = oDOM.CreateElement( "SecondChild" )
o1.Text = "Don't forget me, the Second Child Element"
oRoot.AppendChild( o1)

; set up a parsing instruction
oP     = oDOM.CreateProcessingInstruction( "xml", 'version="1.0"' )
oIns   = oDOM.ChildNodes(0)
oDOM.InsertBefore( oP, oIns )

;save the data to file
oDOM.Save( file )

ObjectClose( oDOM )

RunWait( "notepad", file )
exit


Article ID:   W15367
File Created: 2002:09:05:13:51:28
Last Updated: 2002:09:05:13:51:28