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

ADO

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

Reading from an XML File

Keywords: 	 XML

Question:

Can Winbatch handle XML? for example if some data needs to be extracted from some XML text is there any templates or filtering extension available or planned for Winbatch to handle this?

Answer:

Not currently, however a number of people do work with XML files, understanding the XML file and burrowing down to the desired data.

Here's some code that Stan Littlefield posted a while back. Stan figures out some amazing stuff!

Here are a few caveats:

If you have problems opening your XML file:

You may need an app called msPersist. msPersist comes with MDAC ( free download from Microsoft ), or it may be installed as part of Microsofts XML Parser 3.0 setup for IE. msPersist is an MDAC driver that opens or saves recorset data in a very strictly defined Micorsoft-Only format - If your XML file is in any other XML format (of which there could be millions ) normally a DTD or Schema helps identify the 'columns' and or data types. It basically permits opening any XML file as if it were an ADO Recordset, and hence you may re-write the data to LAFF or anything else.

You may also try working with the XMLDom object which is useful for XML data not maintained in the standard MS Recordset Format. The XMLDom is the OLE interface you would need to parse XML in formats other than the Microsoft-Only format.

Otherwise, since XML is just ASCII with a attitude - you could write specific low-level parsers with the FileOpen()... FileRead()... functions in Winbatch to read an XML file.


;/////////////////////////////////////////////////////////////////////////;
;// WINBATCH - Utility Program for Laff Extender /;
;// - Puts Data from Microsoft XML File into a /;
;// comma-delimited Wil Database suitable for manipulation /;
;// with the LAFF Extender (file extension is .LAF) /;
;// /;
;// NOTE - very generic, no error-checking /;
;// /;
;// Stan Littlefield December 3, 2001 /;
;/////////////////////////////////////////////////////////////////////////;

#DefineFunction Populate(RS,handle)
flds = RS.Fields
nCnt = flds.Count

For i=0 TO nCnt-1
fld = RS.Fields(i)
dbNameColumn(handle, i+1, fld.Name)
dbBindCol(handle, i+1, StrCat("v",fld.Name))
Next

x = 0

While ! RS.Eof()
For i=0 TO nCnt-1
fld = RS.Fields(i)
v = StrCat("v",fld.Name)
%v% = fld.Value
Next
x = dbSetEntireRecord(handle,x, 4+16)
dbSave(handle,"","")
RS.MoveNext()
EndWhile
Return("")
#EndFunction

AddExtender("laffd34i.dll")

cXML = AskFileName("Select XML File",".\","XML Files|*.xml|","*.xml",1)
If cXML == ""
exit
Endif

RS = ObjectOpen("ADODB.RecordSet")
cLAF = StrReplace(StrUpper(cXML),".XML",".LAF")
handle = dbOpen (cLAF,1, 2, 4, 0, ',',"")

BoxOpen("Opening %cXML%","Creating %cLAF%")
IF FileExist(cLAF) Then FileDelete(cLAF)

RS.Open(cXML,"Provider=MSPersist;",,,256)
RS.MoveFirst()
Populate(RS,handle)
ObjectClose(RS)
dbClose(handle)
BoxShut()

Exit 

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