使用Classic ASP从XML中重新传输数据

时间:2016-01-19 15:38:24

标签: xml parsing asp-classic

我正在尝试使用经典ASP从XML文件中检索数据,而xml几乎是10 MB。

我收到的数千条记录没有任何问题但是在某一时刻脚本停止并在第23行发出错误“Object Required error 800a01a8”

23与其他人相同:

Dim barkod1 : barkod1 = xmlProduct.selectSingleNode("barkod").text

整个脚本在这里:

<%   

Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")    
objXMLDoc.async = False    
objXMLDoc.load Server.MapPath("ProductList3.xml")

Dim xmlProduct       
For Each xmlProduct In objXMLDoc.documentElement.selectNodes("urun")

	 Dim sira : sira = xmlProduct.selectSingleNode("sira").text   
     Dim urunKodu1 : urunKodu1 = xmlProduct.selectSingleNode("urunKodu1").text   
     Dim ureticikodu : ureticikodu = xmlProduct.selectSingleNode("ureticikodu").text   
     Dim urunAdi : urunAdi = xmlProduct.selectSingleNode("urunAdi").text   
     Dim fiyat1 : fiyat1 = xmlProduct.selectSingleNode("fiyat1").text   
     Dim fiyatcinsi1 : fiyatcinsi1 = xmlProduct.selectSingleNode("fiyatcinsi1").text   
     Dim kdvdurumu : kdvdurumu = xmlProduct.selectSingleNode("kdvdurumu").text   
     Dim kdvorani : kdvorani = xmlProduct.selectSingleNode("kdvorani").text   
     Dim garantisuresi : garantisuresi = xmlProduct.selectSingleNode("garantisuresi").text   
     Dim stok : stok = xmlProduct.selectSingleNode("stok").text
     Dim birim : birim = xmlProduct.selectSingleNode("birim").text
     Dim marka : marka = xmlProduct.selectSingleNode("marka").text
     Dim katmannumarsi : katmannumarsi = xmlProduct.selectSingleNode("katmannumarsi").text
     Dim barkod1 : barkod1 = xmlProduct.selectSingleNode("barkod").text
     Dim resim0 : resim0 = xmlProduct.selectSingleNode("resim0").text
     Dim resim1 : resim1 = xmlProduct.selectSingleNode("resim1").text
     
          
	 
     Response.Write "<b>Sıra:</b>" & Server.HTMLEncode(sira) & "<br> "
     Response.Write "<b>urunKodu1:</b>" & Server.HTMLEncode(urunKodu1) & "<br>"   
     Response.Write "<b>ureticikodu:</b>" & Server.HTMLEncode(ureticikodu) & "<br>"   
     Response.Write "<b>urunAdi:</b>" & Server.HTMLEncode(urunAdi) & "<br>"   
     Response.Write "<b>fiyat1:</b>" & Server.HTMLEncode(fiyat1) & "<br>"   
     Response.Write "<b>fiyatcinsi1:</b>" & Server.HTMLEncode(fiyatcinsi1) & "<br>"   
     Response.Write "<b>kdvdurumu:</b>" & Server.HTMLEncode(kdvdurumu) & "<br>"   
     Response.Write "<b>kdvorani:</b>" & Server.HTMLEncode(kdvorani) & "<br>"   
     Response.Write "<b>garantisuresi:</b>" & Server.HTMLEncode(garantisuresi) & "<br>"   
     Response.Write "<b>Stok:</b>" & Server.HTMLEncode(stok) & "<br>"   
     Response.Write "<b>birim:</b>" & Server.HTMLEncode(birim) & "<br>"   
     Response.Write "<b>marka:</b>" & Server.HTMLEncode(marka) & "<br>"   
     Response.Write "<b>Barkod:</b>" & Server.HTMLEncode(barkod1) & "<br>"   
     Response.Write "<b>resim0:</b>" & Server.HTMLEncode(resim0) & "<br>"   
     Response.Write "<b>resim1:</b>" & Server.HTMLEncode(resim1) & "<br>"   
     Response.Write "<b>katmannumarsi:</b>" & Server.HTMLEncode(katmannumarsi) & "<br>---------------<br>"   
     
Next   

我不知道在哪一点上我失败但我认为这可能是因为原始的XML文件大小所以也许我可以保持脚本一段时间直到xml完全加载然后运行我的脚本?你们有什么感想?

以下是原始XML文件的示例记录

<root><urun><sira>0000000</sira><urunKodu1>2000021</urunKodu1><ureticikodu>ABC</ureticikodu><urunAdi>ABC</urunAdi><fiyat1>1,00</fiyat1><fiyatcinsi1>USD</fiyatcinsi1><kdvdurumu>0</kdvdurumu><kdvorani>18</kdvorani><garantisuresi>0</garantisuresi><stok>5+</stok><birim>ADET</birim><marka>XYZ</marka><katmannumarsi>8000</katmannumarsi><barkod>8697671413127</barkod><resim0>https://www.XXX.XX.XX/AAA/BBB/S/21_1.jpg</resim0><resim1>https://www.XXX.XX.XX/AAA/BBB/L/21_1.jpg</resim1><ozellik tanim="Kategori">ABC </ozellik><ozellik tanim="Marka">ABC</ozellik><ozellik tanim="Açıklama">-</ozellik><ozellik tanim="Model Link">-</ozellik><ozellik tanim="Model Soft">-</ozellik><ozellik tanim="Model Dosya">-</ozellik></urun></root>

1 个答案:

答案 0 :(得分:0)

如果节点存在,您可以编写这样的函数来获取文本:

function getText(theNode)
    if theNode is Nothing then
        getText=""
    else
        getText = theNode.text
    end if
end function

并使用它:

'Pass the node in the function
Dim barkod1 : barkod1 = getText(xmlProduct.selectSingleNode("barkod"))

OR

function getText(theNodeName)

    Dim theNodeObj
    set theNodeObj = xmlProduct.selectSingleNode(theNodeName)

    if theNodeObj is Nothing then
        getText=""
    else
        getText = theNodeObj.text
    end if

end function

并使用它:

'Pass the name in the function
Dim barkod1 : barkod1 = getText("barkod")