asp操作xml

时间:2014.01.05 发布人:healthgxl

asp操作xml

已解决问题

谷歌healthgxl用户在2014.01.05提交了关于“比亚迪f3asp操作xml”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-11-14T13:14:01。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,你是我的宝贝,你是我的花,谢谢你对我的帮助!

希望以下的回答,能够帮助你。

第1个回答

用户名:twsnwl  

增加、删除、修改“XML记录”来自的例子
"XML文件
<?xmlversion="1.0"encoding="gb2312"?>
<stocksdate="2001-8-24">
<stock>
<code>111</code>
<name>AAA</na吗原执me>
<openprice>7.93</openpric331215问答e>
<currentpr美记笑语苏跳帮ice>7.93</currentprice>
<tradeamount>0</tradeamount>
<totalamount>1000000</t故用绍川otalamount>
<status>1</status>
</stock>
<stock>
<code>222</code>
<name>**B</name>
<openprice>170.92</openprice>
<currentprice>170.92</currentprice>
<tradeamount>0</tradeamount>
<totalamount>100000</totalamount>
<status>1</status>
</stock>
<stock>
<c林期刻扬请个后ode>333</code>
<name>CCC</name>
<openprice>55.43</openprice>
<currentpric取血货律e>55.43</cur移价频者北友艺她般rentprice>
<tradeamount>0</tradeamount>
<totalamount>100000</totalamount>
<status>1</status></stock>
</stocks>

"处理文件Stoc配错算日不别取你死ks.asp
<%
Response.CacheControl="no-cache"
%>
<html>
<head>

<title>XML的股票行情</title>
<style>
td{font-size:9pt}
</style>
</head>

<body>
<h1>XML的股票行情</h1>

<hr>
<%
setxml=Server.杂坏技的呀多冷势目操联CreateObject("MSXML2.domdocumen能套t")
"setxml=Server.CreateObject("Microsoft.xmlDom")
xml.loadServer.MapPath("stock吗调钟能上植友劳底s.xml")
ifxml.parseError.errorCode<>0then
Response.Write"xml.parseError.errorCode="&xml.parseError.errorCode
Response.Write"x根针沉调促行刻针影课ml.parseE客友价序整序书rror.reason="&xml.parseError.reason
Response.Write"xml.parseError架.line="&xml.parseError.line
Response.End
endif

"如果<stocks>的DATE属性不是今天,则改为今天
xml企接者Date=xml.documentElement.attributes.getNamedItem("date").text
ifdatediff("d",xmlDate,date)>=1then
"xml.documentElement.attributes.getNamedItem("date").text=FormatDateTime(date,2)
""可以在此加入改变股票价格的代码
i=1
StockAmount=xml.getElementsByTagName("stock").length
setStockList=xml.getElementsByTagName("stock")
fori=0toStockAmoun粒t-1
setStockTemp=StockList.item(i)
ra茶ndomize
s针厂场s=1
ifrnd(夫各下态卷越等)>0.6thenss=-1
randomize
StockTemp.childNodes.item(2).text=FormatNumber(Ccur(StockTemp.childNodes.item(2).text)*(1+ss*rnd()/10),2)
StockTemp.childNodes.item(3).text=StockTemp.childNodes.item(2).text
next

***.s**eServer.MapPath("stocks.xml")
endif

ifRequest.Form("submit")="增加股票"then

setobjRoot=xml.documentElement
setnewStock=xml.createElement("stock")
objRoot.appendChildnewStock
setobjA1=xml.createElement("code")
newStock.appendChildobjA1
objA1.text=Request.Form("scode")
setobjA2=xml.createElement("name")
newStock.appendChildobjA2
objA2.text=Request.Form("sname")
setobjA3=xml.createElement("openprice")
newStock.appendChildobjA3
objA3.text=Request.Form("openPrice")
setobjA4=xml.createElement("currentprice")
newStock.appendChildobjA4
objA4.text=Request.Form("curPrice")
setobjA5=xml.createElement("tradeamount")
newStock.appendChildobjA5
objA5.text=Request.Form("tradeAmount")
setobjA6=xml.createElement("totalamount")
newStock.appendChildobjA6
objA6.text=Request.Form("TotalAmount")
setobjA7=xml.createElement("status")
newStock.appendChildobjA7
objA7.text=Request.Form("status")

***.s**eServer.MapPath("stocks.xml")

setnewStock=nothing
setobjRoot=nothing
setobjA1=nothing
setobjA2=nothing
setobjA3=nothing
setobjA4=nothing
setobjA5=nothing
setobjA6=nothing
setobjA7=nothing

endif

ifRequest.Form("submit")="删除"andRequest.Form("remove")<>emptythen
setobjCodeList=xml.getElementsByTagName("code")
remove=split(Request.Form("remove"))
fori=0toubound(remove)
forj=0toobjCodeList.Length-1
ifobjcodeList.item(j).text=remove(i)then
xml.documentElement.removeChild(objcodeList.item(j).parentNode)
endif
next
***.s**eServer.MapPath("stocks.xml")
next
endif

"***.s**eServer.MapPath("stocks.xml")

Response.WriteFormatDateTime(now)
%>
<hr>
<formaction=""method="post">
<TABLEcellSpacing=1cellPadding=1width="100%"border=1>
<TR>
<TD>股票代码</TD>
<TD>股票名称</TD>
<TD>开盘价格</TD>
<TD>当前价格</TD>
<TD>成交量</TD>
<TD>流通总数</TD>
<TD>状态</TD>
<TD>删除</TD>
</TR>
<%
i=1
StockAmount=xml.getElementsByTagName("stock").length
setStockList=xml.getElementsByTagName("stock")
fori=0toStockAmount-1
setStockTemp=StockList.item(i)
%>
<TR>
<TD><%=StockTemp.childNodes.item(0).text%></TD>
<TD><%=StockTemp.childNodes.item(1).text%></TD>
<TD><%=StockTemp.childNodes.item(2).text%></TD>
<TD><%=StockTemp.childNodes.item(3).text%></TD>
<TD><%=StockTemp.childNodes.item(4).text%></TD>
<TD><%=StockTemp.childNodes.item(5).text%></TD>
<TD><%=StockTemp.childNodes.item(6).text%></TD>
<TD><inputtype="checkbox"name="remove"value=<%=StockTemp.childNodes.item(0).text%>></TD>
</TR>
<%
next
setxml=nothing
%>
<TR>
<TD><inputtype="text"name="scode"></TD>
<TD><inputtype="text"name="sname"></TD>
<TD><inputtype="text"name="openPrice"size="6"></TD>
<TD><inputtype="text"name="curPrice"size="6"></TD>
<TD><inputtype="text"name="tradeAmount"></TD>
<TD><inputtype="text"name="TotalAmount"></TD>
<TD><inputtype="text"name="status"size="6"></TD>
<TD><inputtype="submit"name="submit"value="删除"></TD>
</TR>
</TABLE>
<%
%>
<inputtype="submit"name="submit"value="增加股票">
</form>
</body>
</html>