Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: Leggere un xml da asp

  1. #1

    Leggere un xml da asp

    Salve a tutti,

    ho il seguente problema :

    io ho creato nel "Sito A" un file asp che mi restituisce un xml dinamico"

    io ora devo leggere da un "Sito B" questo xml e visualizzare i dati in una tabella html

    ho trovato questo esempio :

    <%
    url = "http://localhost/areainformaticasrl/rss.asp"

    'Creo oggetto DOM XML
    set objXml = server.CreateObject("msxml2.DOMDocument.3.0")
    objXml.async = false
    objXml.setProperty "ServerHTTPRequest", True

    'validazione del documento Xml
    objXml.validateOnParse = false

    'non conservare spazi
    objXml.preserveWhiteSpace = false

    blnLoaded = objXml.Load(url)

    If Not blnLoaded then
    response.write("nessuna news presente")
    Else
    'codice per visualizzare i dati
    End if

    ora il problema è questo : se questo codice punta a un file .xml tutto bene e funziona perfettamente

    mentre se punto a un file .asp lui non lo riconosce xml e mi riesce a caricare il file nell'oggetto

    C'è un altro metodo dell'oggetto che ti consente di recuperare un file xml da un file con estensione diversa da .xml?

    Aspetto fiducioso

  2. #2
    Utente di HTML.it L'avatar di kluster
    Registrato dal
    Jul 2003
    Messaggi
    1,288
    non vorrei che le prestazioni si abbassasero e quindi valuta se ci sono altri metodi cmq prova con un oggetto xmlHttp
    il 4.0 è + veloce se non è installato prova con
    ("MSXML2.ServerXMLHTTP")
    codice:
     
    Set ServerHTTP = CreateObject("MSXML2.ServerXMLHTTP.4.0")
    ServerHTTP.open "GET",url,false
    ServerHTTP.Send
    XmlResult = ServerHTTP.responseXML
    .....
    .....
    blnLoaded = objXml.Load(XmlResult)
    .....
    .....

  3. #3
    ok

    ho provato e non da errore ma mi restituisce false la variabile di controllo quindi non visualizza niente

    questo è il codice :

    <%

    url = "http://localhost/rss.asp"

    Set ServerHTTP = CreateObject("MSXML2.ServerXMLHTTP.4.0")
    ServerHTTP.open "GET",url,false
    ServerHTTP.Send
    XmlResult = ServerHTTP.responseXML.xml




    'Script Asp che rielabora un documento xml Rss e crea in output un documento Html
    'response.write(url)

    'Creo oggetto DOM XML
    set objXml = server.CreateObject("msxml2.DOMDocument.3.0")
    objXml.async = false
    objXml.setProperty "ServerHTTPRequest", True

    'validazione del documento Xml
    objXml.validateOnParse = false

    'non conservare spazi
    objXml.preserveWhiteSpace = false

    'blnLoaded = objXml.Load(url)
    blnLoaded = objXml.Load(XmlResult)
    response.write(blnLoaded)
    If Not blnLoaded then
    response.write("Nessun prodotto da visualizzare")
    Else
    html = "<table width=""400"">"
    set objNodeList = objXml.getElementsByTagName("channel")

    for each objNode in objNodeList
    for each objNode2 in objNode.childNodes
    Select Case objNode2.nodeName
    Case "title"
    html = html & "<tr><td>"
    html = html & objNode2.firstChild.nodevalue
    html = html & "
    </td></tr>"
    Case "language"
    html = html & "<tr><td>"
    html = html & objNode2.firstChild.nodevalue
    html = html & "</td></tr>"
    Case "description"
    html = html & "<tr><td>"
    html = html & objNode2.firstChild.nodevalue
    html = html & "
    </td></tr>"
    End Select
    next
    next
    html = html & "</table>"
    html = html & "
    <hr>
    "

    html = html & "<table width=""100%"">"
    html = html & "<tr><td>Id Prodotto</td><td>Nome prodotto</td><td>Categoria</td><td>Marca</td>"
    html = html & "<td>Prezzo</td><td>Codice</td></tr>"

    set objNodeList = nothing

    set objNodeList = objXml.getElementsByTagName("item")
    for each objNode in objNodeList
    for each objNode2 in objNode.childNodes
    Select Case objNode2.nodeName
    Case "idprodotto"
    idprodotto = objNode2.firstChild.nodevalue
    Case "prodotto"
    prodotto = objNode2.firstChild.nodevalue
    Case "categoria"
    categoria = objNode2.firstChild.nodevalue
    Case "marca"
    marca = objNode2.firstChild.nodevalue
    Case "prezzo"
    prezzo = objNode2.firstChild.nodevalue
    Case "codice"
    codice = objNode2.firstChild.nodevalue
    End Select
    next
    html = html & "<tr><td>" & idprodotto & "</td><td>" & prodotto & "</td><td>" & categoria & "</td><td>" & marca & "</td>"
    html = html & "<td>" & prezzo & "</td><td>" & codice & "</td></tr>"
    next
    html = html & "</table>"
    set objNodeList = nothing
    response.write(html)


    End if

    %>

    e il file rss.asp restituisce questo xml :

    <?xml version="1.0" encoding="UTF-8" ?>
    - <rss version="0.91">
    - <channel>
    <title>Prodotti in offerta</title>
    <description>Elenco dei prodotti in offerta in questo momento</description>
    <language>it</language>
    - <item>
    - <idprodotto>
    - <![CDATA[ 90
    ]]>
    </idprodotto>
    - <prodotto>
    - <![CDATA[ masterizzatore riscrivibile lg 52x32/52x bulk
    ]]>
    </prodotto>
    - <categoria>
    - <![CDATA[ cd-rw / dvd-rw
    ]]>
    </categoria>
    - <marca>
    - <![CDATA[ lg
    ]]>
    </marca>
    - <prezzo>
    - <![CDATA[ 25,08
    ]]>
    </prezzo>
    - <codice>
    - <![CDATA[ malg12
    ]]>
    </codice>
    </item>
    - <item>
    - <idprodotto>
    - <![CDATA[ 33
    ]]>
    </idprodotto>
    - <prodotto>
    - <![CDATA[ amd xp 2400+ box 3anni garanzia
    ]]>
    </prodotto>
    - <categoria>
    - <![CDATA[ processori
    ]]>
    </categoria>
    - <marca>
    - <![CDATA[ amd
    ]]>
    </marca>
    - <prezzo>
    - <![CDATA[ 71,1
    ]]>
    </prezzo>
    - <codice>
    - <![CDATA[ cpk7240b
    ]]>
    </codice>
    </item>
    - <item>
    - <idprodotto>
    - <![CDATA[ 39
    ]]>
    </idprodotto>
    - <prodotto>
    - <![CDATA[ intel celeron 2400 socket 478 boxato
    ]]>
    </prodotto>
    - <categoria>
    - <![CDATA[ processori
    ]]>
    </categoria>
    - <marca>
    - <![CDATA[ intel
    ]]>
    </marca>
    - <prezzo>
    - <![CDATA[ 64,97
    ]]>
    </prezzo>
    - <codice>
    - <![CDATA[ cpc2400b
    ]]>
    </codice>
    </item>
    </channel>
    </rss>

  4. #4
    Utente di HTML.it L'avatar di kluster
    Registrato dal
    Jul 2003
    Messaggi
    1,288
    XmlResult = ServerHTTP.responseXML.xml ?

    prova ServerHTTP.responseXML

  5. #5
    si perchè l'altro modo mi dava errore (metodo non supportato) e vedendo la guida di riferimento ho visto un esempio che usava responseXML.xml

  6. #6
    Utente di HTML.it L'avatar di kluster
    Registrato dal
    Jul 2003
    Messaggi
    1,288
    aspe, forse non è la versione adatta cerco un attimo
    il metodo LoadUrl carica anche una stringa giusto?
    prova intanto con ResponseText

  7. #7
    Utente di HTML.it L'avatar di kluster
    Registrato dal
    Jul 2003
    Messaggi
    1,288
    set ServerHTTP= Server.CreateObject("Microsoft.XMLHTTP")
    ServerHTTP.Open "GET", URL, false
    ServerHTTP.Send
    XmlResult = ServerHTTP.responseXML

  8. #8
    stessa cosa :

    Tipo di errore:
    Errore di run-time di Microsoft VBScript (0x800A01B6)
    Proprietà o metodo non supportati dall'oggetto: 'XmlResult'

    con responseText va però mi restituisce sempre false quindi non riesce a caricare l'xml

  9. #9
    Utente di HTML.it L'avatar di kluster
    Registrato dal
    Jul 2003
    Messaggi
    1,288
    non so che altro dirti mickey,non vorrei fosse una cavolata ma
    fossi nella tua situazione proverei a salvare con FSO su disco l'xml e poi caricarlo con il Load, di + nin zo

  10. #10
    si è un'idea che avevo valutato, però per fare questo dovrei schedulare ogni giorno un file asp che esegue quello che hai detto

    oppure farlo lanciare ogni giorno al primo utente che accede al sito

    quindi preferivo provare lo scambio dei dati in questo modo.

    Cmq in .Net è una cavolata simulare questa situazione

    vabbè grazie lo stesso cmq


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.