By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,802 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

connecting to external xml file

P: n/a
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
May 28 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

May 28 '06 #2

P: n/a
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

May 28 '06 #3

P: n/a

"Brian Quigley" <qu******@iol.ie> wrote in message
news:e5**********@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))
May 29 '06 #4

P: n/a

"Brian Quigley" <qu******@iol.ie> wrote in message
news:e5**********@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.FreeThreadedDOMDocumen t.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
May 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.