经典ASP阅读子节点和其他元素

时间:2014-12-09 13:33:15

标签: xml asp-classic xml-parsing

嗯,嘿,伙计们。在没有写一个代码超过三年之后,我不得不与来自儿童社区的老朋友ASP见面。我的事情是,我需要从经典的asp中读取XML中的一些数据。这里有两个元素。我决定将所有内容放在一个文本文件中,根据文本文档制作另一个好的和可编辑的xml文件。我成功地从一个元素获取数据但我陷入了第二个元素。我怎样才能进入第二部分并从那里获取数据?

这是我的xml

示例

<root>
<urun>
<sira>1</sira>
<urunkodu1>Number</urunkodu1>
<urunkodu2>Some Other numbers</urunkodu2>
<ureticikodu>Other numbers too</ureticikodu>
<urunadi>Model</urunadi>
<fiyat1>Price with number</fiyat1>
<fiyatcinsi1>currency</fiyatcinsi1>
<kdvdurumu>tax</kdvdurumu>
<kdvorani>tax percentage</kdvorani>
<garantisuresi>guarantee</garantisuresi>
<stok>1</stok>
<birim>piece</birim>
<marka>Product Name</marka>
<katman>Product Class</katman>
<altkatman1>Brand</altkatman1>
<ozellik tanim="Processor">
Intel® Core™ bla bla bla
</ozellik>
<ozellik tanim="Chipset"/>
<ozellik tanim="Screen">000</ozellik>
<ozellik tanim="RAM">4GB DDR3 1600 MHz</ozellik>
<ozellik tanim="HDD">500GB 5400 Rpm</ozellik>
<ozellik tanim="Graphic>NVIDIA GeForce 820M</ozellik>
<ozellik tanim="Sound card"/>
<ozellik tanim="Optical Driver">SuperMulti DVD</ozellik>
<ozellik tanim="Fax / Modem"/>
<ozellik tanim="Networ">Ethernet LAN 10/100</ozellik>
<ozellik tanim="Wireless">802.11b/g/n, Bluetooth® 4.0</ozellik>
<ozellik tanim="battery">4 hücreli Li-ion batarya</ozellik>
<ozellik tanim="expansion"/>
<ozellik tanim="I/O">2x USB 3.0, 2x USB 2.0, 1x HDMI</ozellik>
<ozellik tanim="os">FreeDOS</ozellik>
<ozellik tanim="keyboard / Fare">Numerik Q TR</ozellik>
<ozellik tanim="size">2.38 Kg</ozellik>
<ozellik tanim="built in web cam>Var</ozellik>
<ozellik tanim="guarantee"/>
<ozellik tanim="case"/>
<aciklama1/>
<aciklama2/>
<aciklama3/>
<resim0>https://www.pictureurl.com/picture.jpg</resim0>
<resim1>https://www.pictureurl.com/picture.jpg</resim1>
<resim2>https://www.pictureurl.com/picture.jpg</resim2>
<resim3>https://www.pictureurl.com/picture.jpg</resim3>
</urun>

所以, 经过一点点搜索和大脑融化,我做了类似的事情,

<%
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("c:\inetpub\wwwroot\xml\urunler.txt")

vurl = "http://myxmlsource/myfirstxml.asp?id=1"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False
http.Send

Set dom = http.responseXML

Set items = dom.getElementsByTagName("urun")
For Each item In items

    Set sira = item.getElementsByTagName("sira")
    If NOT (sira IS Nothing) Then 
        var_sira = sira(0).Text
    End If
	
	Set urunkodu1 = item.getElementsByTagName("urunkodu1")
    If NOT (urunkodu1 IS Nothing) Then 
        var_urunkodu1 = urunkodu1(0).Text
    End If
	
	Set urunkodu2 = item.getElementsByTagName("urunkodu2")
    If NOT (urunkodu2 IS Nothing) Then 
        var_urunkodu2 = urunkodu2(0).Text
    End If
	
	Set ureticikodu = item.getElementsByTagName("ureticikodu")
    If NOT (ureticikodu IS Nothing) Then 
        var_ureticikodu = ureticikodu(0).Text
    End If
	
	Set urunadi = item.getElementsByTagName("urunadi")
    If NOT (urunadi IS Nothing) Then 
        var_urunadi = urunadi(0).Text
    End If
	
		Set fiyat1 = item.getElementsByTagName("fiyat1")
    If NOT (fiyat1 IS Nothing) Then 
        var_fiyat1 = fiyat1(0).Text
    End If
	
			Set fiyatcinsi1 = item.getElementsByTagName("fiyatcinsi1")
    If NOT (fiyatcinsi1 IS Nothing) Then 
        var_fiyatcinsi1 = fiyatcinsi1(0).Text
    End If
	
	Set kdvdurumu = item.getElementsByTagName("kdvdurumu")
    If NOT (kdvdurumu IS Nothing) Then 
        var_kdvdurumu = kdvdurumu(0).Text
    End If
	
	Set kdvorani = item.getElementsByTagName("kdvorani")
    If NOT (kdvorani IS Nothing) Then 
        var_kdvorani = kdvorani(0).Text
    End If
	
	Set garantisuresi = item.getElementsByTagName("garantisuresi")
    If NOT (garantisuresi IS Nothing) Then 
        var_garantisuresi = garantisuresi(0).Text
    End If
	
		Set stok = item.getElementsByTagName("stok")
    If NOT (stok IS Nothing) Then 
        var_stok = stok(0).Text
    End If
	
		Set birim = item.getElementsByTagName("birim")
    If NOT (birim IS Nothing) Then 
        var_birim = birim(0).Text
    End If
	
		Set marka = item.getElementsByTagName("marka")
    If NOT (marka IS Nothing) Then 
        var_marka = marka(0).Text
    End If
	
			Set katman = item.getElementsByTagName("katman")
    If NOT (katman IS Nothing) Then 
        var_katman = katman(0).Text
    End If

			Set altkatman1 = item.getElementsByTagName("altkatman1")
    If NOT (altkatman1 IS Nothing) Then 
        var_altkatman1 = altkatman1(0).Text
    End If

	


	
tfile.WriteLine var_sira & "%" & var_altkatman1


    response.write "Sira: "&var_sira&"</br>"
	response.write "Urunkodu1: "&var_urunkodu1&"</br>"
	response.write "Urunkodu2: "&var_urunkodu2&"</br>"
	response.write "Ureticikodu: "&var_ureticikodu&"</br>"
	response.write "Urunadi: "&var_urunadi&"</br>"
	response.write "fiyat1: "&var_fiyat1&"</br>"
	response.write "fiyatcinsi1: "&var_fiyatcinsi1&"</br>"
	response.write "kdvdurumu: "&var_kdvdurumu&"</br>"
	response.write "kdvorani: "&var_kdvorani&"</br>"
	response.write "garantisuresi: "&var_garantisuresi&"</br>"
	response.write "stok: "&var_stok&"</br>"
	response.write "birim: "&var_birim&"</br>"
	response.write "marka: "&var_marka&"</br>"
	response.write "katman: "&var_katman&"</br>"
	response.write "altkatman1: "&var_altkatman1&"</br>"
	
	
	response.write "</br>"
	Next
	
	tfile.close
set tfile=nothing
set fs=nothing
%>

0 个答案:

没有答案