網頁設計 : 在網頁上讀取遠程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
|
這裡