For Programmers: Free Programming Magazines  


Home > Archive > ASP > May 2006 > connecting to external xml file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author connecting to external xml file
Brian Quigley

2006-05-28, 6:56 pm

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.transformNode(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=schedule&order=code"
stylef = "page1.xsl"
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.validateOnParse = false
xmlDoc.load(xmlf)
xslDoc.load(Server.Mappath(stylef))
Response.Write(xmlDoc.transformNode(xslDoc))

any suggestions ? the page in question is
http://www.bestoutcomes.ie/tcclist.asp

thanks, Brian


surf_doggie

2006-05-28, 6:56 pm

Have you put any debug in?

xmlDoc.load(xmlf)
if isObject(xmlf) = true then
if xmlDoc.parseerror.errorcode <> 0 then
response.write "Error Code : " & xmlDoc.parseerror.errorcode &
"<BR>"
response.write "Reason : " & xmlDoc.parseerror.reason & "<BR>"
response.write "Error Line : " & xmlDoc.parseError.line & "<BR>"
response.write "String : " & xmlDoc.parseError.srcText & "<BR>"
response.end
End If
else
response.write "Doc Failed to load"
response.end
end if

Earl
www.jhdesigninc.com

surf_doggie

2006-05-28, 6:56 pm

This works on my local machine using your xls. Its not pretty but it
works

<%
stylef = server.mapPath("page1.xsl")
URL="http://localhost/briantest/testPage.asp"
set xmlDoc = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
set xsl = Server.CreateObject("Microsoft.XMLDOM")
set aDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.open "Get", URL, False
xmlDoc.send
aDoc.Load(xmlDoc.responseText)
xsl.load(stylef)
Response.Write(aDoc.transformNode(xsl)) 'this is the line
thats t
Set aDoc=Nothing
set xmlDoc = Nothing
set xsl=Nothing
%>

Earl
www.jhdesigninc.com

Anthony Jones

2006-05-29, 7:56 am


"Brian Quigley" <quigleyb@iol.ie> wrote in message
news:e5ccp4$dja$1@reader01.news.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.transformNode(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=schedule&ord
er=code"
> stylef = "page1.xsl"
> set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
> set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
> xmlDoc.validateOnParse = false
> xmlDoc.load(xmlf)
> xslDoc.load(Server.Mappath(stylef))
> Response.Write(xmlDoc.transformNode(xslDoc))
>
> any suggestions ? the page in question is
> http://www.bestoutcomes.ie/tcclist.asp
>
> thanks, Brian
>
>


Try this:-
xmlf =
"http://www.tcc-net.com/associates/xml/coursesopen.php?fieldSet=schedule&ord
er=code"
stylef = "page1.xsl"
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xslDoc.async = false
xmlDoc.validateOnParse = false
xmlDoc.load(xmlf)
xslDoc.load(Server.Mappath(stylef))
Response.Write(xmlDoc.transformNode(xslDoc))


Anthony Jones

2006-05-29, 7:56 am


"Brian Quigley" <quigleyb@iol.ie> wrote in message
news:e5ccp4$dja$1@reader01.news.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.transformNode(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=schedule&ord
er=code"
> stylef = "page1.xsl"
> set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
> set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
> xmlDoc.validateOnParse = false
> xmlDoc.load(xmlf)
> xslDoc.load(Server.Mappath(stylef))
> Response.Write(xmlDoc.transformNode(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.CharSet 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("http://www.tcc-net.com/associates/xml/coursesopen.php?fieldSet=
schedule&order=code")
Set oTemplate = GetTemplate("Page1.xsl", "xslPage1")

Response.ContentType = "text/html"
Response.CharSet = "UTF-8"

Set oProc = oTemplate.createProcessor()
oProc.input = xmlDoc
oProc.output = Response
oProc.Transform

Function GetDocument(src)
Set GetDocument = Server.CreateObject("MSXML2.DOMDocument.3.0")
GetDocument.async = False
GetDocument.validateOnParse = False
GetDocument.load(src)
End Function

Function GetTemplate(src, name)
Dim domXSL

If Not IsEmpty(Application(name)) Then

Set domXSL = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
domXSL.async = False
domXSL.load(Server.MapPath("src"))

Set GetTemplate = Server.CreateObject("MSXML2.XSLTemplate.3.0")
Set GetTemplate.stylesheet = domXSL
Set Application(name) = GetTemplate
Else
Set GetTemplate = Application(name)
End If

End Function


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com