網頁設計 : 在網頁上讀取遠程xml的數據-Xml程式編輯教程

一個客戶提供一個股價既資訊,要求放在頁面上,顯示一d數據,需要從遠程獲取xml,然後解析寫在網頁上,開始唔會覺得好難,其實蠻簡單的,先用javascript寫了一個:

以下為引用的內容:

<script language=javascript>
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("http://****.com/scripts/****.asp?subcode=C22");
nodes = xmlDoc.documentElement.childNodes;
var text = xmlDoc.selectSingleNode("//last").text
document.write(text);
</script>


http://****.com/scripts/****.asp?subcode=C22 ,是客戶提供的頁面,其實是xml的內容,這裡直接調用windows的組件進行讀取,然後調用其中一個selectSingleNode的方法,讀出last字段的內容;
VBscript也寫了一個,其實差不多,不過有一點不同,asp中VB的不能直接讀取遠程xml的內容,很奇怪,不知道是不是由於VB的限制:

以下為引用的內容:

dim XMLMorntekDocument
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET","http://****com/scripts/******.asp?subcode=C22",False
http.send
Set XMLMorntekDocument=Server.CreateObject("Microsoft.XMLDOM")
XMLMorntekDocument.Async=False
XMLMorntekDocument.ValidateOnParse=False
XMLMorntekDocument.Load(http.ResponseXML)
price = XMLMorntekDocument.selectSingleNode("//last").text
response.write price
Set http=Nothing
Set XMLMorntekDocument=Nothing



這裡

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dettori 的頭像
    dettori

    Web Design

    dettori 發表在 痞客邦 留言(0) 人氣()