"Brian Quigley" <qu******@iol.i e> wrote in message
news:e5******** **@reader01.new s.esat.net...
Hi,
i am trying to write a script to parse an external xml file, but am having
problems... the problem i think has to do with me trying to do
Response.Write( xmlDoc.transfor mNode(xslDoc)) before the xml is fully
loaded. The link to the xml file is valid. my code is as follows...
xmlf =
"http://www.tcc-net.com/associates/xml/coursesopen.php ?fieldSet=sched ule&ord
er=code" stylef = "page1.xsl"
set xmlDoc = Server.CreateOb ject("Microsoft .XMLDOM")
set xslDoc = Server.CreateOb ject("Microsoft .XMLDOM")
xmlDoc.validate OnParse = false
xmlDoc.load(xml f)
xslDoc.load(Ser ver.Mappath(sty lef))
Response.Write( xmlDoc.transfor mNode(xslDoc))
any suggestions ? the page in question is
http://www.bestoutcomes.ie/tcclist.asp
thanks, Brian
Brian,
Below is an alternative solution. If you page gets frequent hits it would
be better to cache the xsl transform in the application object and reuse it
on subsequent calls. MSXML has an XSLTemplate object which represents a
parsed, compiled and ready to run xsl transform. Being a Free threaded
object it's safe to store in ASPs application object. Hence the code below
creates on of these and stores it. Subsequent hits on the page can reuse
this object thereby cutting down significant CPU effort.
The CreateProcessor returns an object that will actually transform an XML
DOM to the output. Note that the response object is assigned to the output
property.
In your original code any output generated is converted to a unicode string.
The response.write would then convert the unicode string to the current
codepage for the response or session. In the code below the bytes generated
by the transform will be copied directly to the output buffer without any
code page conversion. This again is more effecient.
The Response.CharSe t is used to specify to the client what character
encoding it is being sent. The code below sets it to UTF-8 because that is
the default used by XSL output. However if your XSL has an encoding
attribute on the xsl:output node you should set the CharSet to the same
value.
Dim oTemplate
Dim oProc
Dim xmlDoc
Set xmlDoc =
GetDocument("ht tp://www.tcc-net.com/associates/xml/coursesopen.php ?fieldSet=
schedule&order= code")
Set oTemplate = GetTemplate("Pa ge1.xsl", "xslPage1")
Response.Conten tType = "text/html"
Response.CharSe t = "UTF-8"
Set oProc = oTemplate.creat eProcessor()
oProc.input = xmlDoc
oProc.output = Response
oProc.Transform
Function GetDocument(src )
Set GetDocument = Server.CreateOb ject("MSXML2.DO MDocument.3.0")
GetDocument.asy nc = False
GetDocument.val idateOnParse = False
GetDocument.loa d(src)
End Function
Function GetTemplate(src , name)
Dim domXSL
If Not IsEmpty(Applica tion(name)) Then
Set domXSL = Server.CreateOb ject("MSXML2.Fr eeThreadedDOMDo cument.3.0")
domXSL.async = False
domXSL.load(Ser ver.MapPath("sr c"))
Set GetTemplate = Server.CreateOb ject("MSXML2.XS LTemplate.3.0")
Set GetTemplate.sty lesheet = domXSL
Set Application(nam e) = GetTemplate
Else
Set GetTemplate = Application(nam e)
End If
End Function