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

OLE with XML

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

MSXML Transformation via OLE


This code takes the bulletin data, extract the node's XML from the document and sends it to the XSL processor for transformation into HTML via OLE.

Overall this file is 122 lines + 45 for the XSL file, compared to the original 228 lines, and no messy clipboard.

Code by Jay Alverson and uses Winbatch 2004F, MSXML 4.0 SP2 & MSIE 6


MS_MSSECURE DATA.WBT

 

#defineSubroutine ShowOLE()
	display(1, "OLE Handles", intcontrol(77, 61, 0, 0, 0))
#endSubroutine

#defineFunction GetXMLNodes(str, file)
	Doc = ObjectOpen(`Msxml2.DOMDocument.4.0`)
	Doc.async = @False		
	Doc.load(file)
	value = ``
	BList = ""
	qstr  = strcat(`//`, str)
	;	retrieve a collection of nodes...
	dNodes = doc.selectNodes(qstr)
	;	loop thru the collection...
	for n = 0 to dNodes.length-1
		;	set the reference to the current node...
		thisNode = dNodes.item(n)
;		message("Debug", GetAttribute(thisNode))
		BList = iteminsert(GetAttribute(thisNode), -1, BList, @tab)
		objectclose(thisNode)
	next
	objectclose(dNodes)
	objectclose(Doc)
	return(BList)
#endFunction

#defineFunction GetAttribute(node)
;	returns a semi-colon delimited list of values for the attributes...
	attributelist = "BulletinID;Title"
	aValueList = ""
	for a = 1 to itemcount(attributelist, ";")
		thisatt = itemextract(a, attributelist, ";")
		aNode = node.getAttributeNode(thisatt)
   	aValue = strreplace(aNode.Value, ";", "...")
		aValueList = iteminsert(aValue, -1, aValueList, ";")
		objectclose(aNode)
	next
	return(aValueList)
#endFunction

#defineFunction GetSingleNode(querystr, file)
;	returns a value for the attribute, based on a pre-constructed query string...
	Doc = ObjectOpen(`Msxml2.DOMDocument.4.0`)
	Doc.async = @False		
	Doc.load(file)
	dValue = ``
	qstr  = strcat(`//`, querystr)
	dNode = doc.selectsingleNode(qstr)
;	message("Debug", dNode.xml)
	xml = dNode.xml
	objectclose(dNode)
	objectclose(Doc)
	return(xml)
#endFunction

#definesubroutine startMSIE(html)
	Browser = ObjectOpen("InternetExplorer.Application")
	Browser.addressbar = @false
	Browser.statusbar = @false
	Browser.menubar = @false
	Browser.toolbar = @false
;	Browser.fullscreen = @true
	url = "c:\Test\NoURL.html"
	browser.navigate(url)
   WaitForPageLoad()
	;	setup the document object...
	browserDoc = Browser.Document
	all = browserdoc.all
	browserdoc.writeln(" ")
	browserdoc.writeln(html)
	browser.visible = @true
	return(browser)
#endsubroutine

#DefineSubroutine WaitForPageLoad()  ; assume Browser
   While browser.busy || browser.readystate == 1
      TimeDelay(0.5)
   EndWhile
   While browser.Document.ReadyState != "complete"
      TimeDelay(0.5)
   EndWhile
   return
#EndSubroutine


#defineFunction TransformViaXSL(xslfile, xml)
	xmlDoc = ObjectOpen("Msxml2.DOMDocument.4.0")
	xmlDoc.async = @False		
	xmlDoc.loadXML(xml)
	;message("Debug", xmlDoc.xml)
	styleDoc = ObjectOpen("Msxml2.DOMDocument.4.0")
	styleDoc.async = @False		
	styleDoc.load(xslfile)
	html = xmlDoc.transformNode(styleDoc)
	objectclose(xmlDoc)
	objectclose(styleDoc)
	return(html)
#endFunction

xmlfile = strcat(dirget(), "ms_mssecure.xml")   				; place data file in same folder...
xslfile = strcat(dirget(), "single node attributes.xsl")		; place XSL  file here too...

BulletinList = GetXMLNodes("Bulletin", xmlfile)
listcount = itemcount(BulletinList, @tab)

while @true

	result = AskItemList("MS Secure XML Bulletin List: %listcount% items.", BulletinList, @tab, @sorted, @single)
	bID = itemextract(1, result, ";")
	;	@ sign is for attributes...
	str = strcat("Bulletin[@BulletinID='", bID, "']")
;	str = strcat("Bulletin[@BulletinID='", "MS00-003", "']")
	transformedHTML =	TransformViaXSL(xslfile, GetSingleNode(str, xmlfile))
	;	start MSIE and put the extracted/formatted data into it...
	br = startMSIE(transformedHTML)

endwhile

return
exit

SINGLE NODE ATTRIBUTES.XSL

<?xml version="1.0"?>
<xsl:stylesheet 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">

<xsl:template match="/">
   <HTML>
      <HEAD>
         <TITLE>Bulletin Summary</TITLE>
      </HEAD>
		<STYLE>
			.EightPoint {font-size: 8pt}
		</STYLE>
      <BODY>
		<!-- place a table around the data... -->
			<table cellpadding="2" cellspacing="2" style="border-collapse: collapse" border="1">
			<!-- insert the template data below here... -->
         <xsl:apply-templates/>
			</table>
      </BODY>
   </HTML>
</xsl:template>

<!-- use the *|@* pattern so that the processor will select both
		regular nodes (*) and attributes (@*), the | symbol means union... -->

<xsl:template match="*|@*">
<tr><td>
<b>
<font color="black" class="EightPoint">
<!-- whether it's an element or attribute, insert its NAME... -->
<xsl:value-of select="name()"/>
</font>
</b>
</td>
<td>
<font color="blue" class="EightPoint">
   <xsl:apply-templates select="*|@*"/>
<!-- whether it's an element or attribute, insert its VALUE... -->
   <xsl:value-of select="."/>
</font>
</td></tr>
</xsl:template>

</xsl:stylesheet>

Article ID:   W16152
File Created: 2004:08:02:11:18:20
Last Updated: 2004:08:02:11:18:20