connecting to external xml file

Discussion in 'ASP General' started by Brian Quigley, May 28, 2006.

  1. 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
    Brian Quigley, May 28, 2006
    #1
    1. Advertising

  2. Brian Quigley

    surf_doggie Guest

    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, May 28, 2006
    #2
    1. Advertising

  3. Brian Quigley

    surf_doggie Guest

    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
    surf_doggie, May 28, 2006
    #3
  4. "Brian Quigley" <> wrote in message
    news:e5ccp4$dja$...
    > 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, May 29, 2006
    #4
  5. "Brian Quigley" <> wrote in message
    news:e5ccp4$dja$...
    > 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:eek:utput 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
    Anthony Jones, May 29, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yw
    Replies:
    2
    Views:
    483
  2. Scott Allen
    Replies:
    8
    Views:
    10,929
    Scott Allen
    May 2, 2004
  3. Big Charles
    Replies:
    3
    Views:
    317
    Alec MacLean
    Oct 29, 2006
  4. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
  5. Mellow Crow
    Replies:
    6
    Views:
    416
    Richard Cornford
    Nov 4, 2005
Loading...

Share This Page