XML文件名为:note.xml,代码如下:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <ServiceResult>
<CurrentPage>1</CurrentPage>
<PageSize>100</PageSize>
<ResultCount>11</ResultCount>
<ResultPages>1</ResultPages>
- <ResultData>
- <TraceTranslates>
<piece>2</piece>
<weight>333</weight>
<code>INFO</code>
- <TraceTranslate>
<AWB_CODE>112-04990930</AWB_CODE>
<FLIGHT_NO>CK261</FLIGHT_NO>
<FLIGHT_DATE>2013-10-11 23:40</FLIGHT_DATE>
<SHIMPENT_PIECE>2</SHIMPENT_PIECE>
<SHIMPENT_WEIGHT>348</SHIMPENT_WEIGHT>
<CARGO_CODE>BKD</CARGO_CODE>
<CARGO_NAME>货物订舱</CARGO_NAME>
<CARGO_ENNAME />
<TRACE_CODE>2521455</TRACE_CODE>
<TRACE_TIME>2013-10-11 23:40</TRACE_TIME>
<TRACE_LOCATION>上海浦东</TRACE_LOCATION>
<AIRPORT_DEP>上海浦东</AIRPORT_DEP>
<AIRPORT_LAND>桃源</AIRPORT_LAND>
<ORIGIN_AIRPORT>上海浦东</ORIGIN_AIRPORT>
<DESTINATION_AIRPORT>桃源</DESTINATION_AIRPORT>
<STARDARD_DATA>BKD 货物订舱: 预订航班CK261(时间 10-11 23:40 地点 上海浦东 机场),2件货物(重量为348KG)</STARDARD_DATA>
<TRACE_DATA>状态名称: 订舱确认<BR/>航站名称: 上海浦东<BR/>航班号: CK261<BR/>日期: 2013-10-11<BR/>时间: 23:40<BR/>状态描述: 货物已订妥指定航班的舱位,计划从 上海浦东 运往 桃源 航班计划起飞时间 2340, 计划到达时间 0105<BR/>件数: 2<BR/>重量: 348</TRACE_DATA>
<OP_TIME>2013-11-15 13:47</OP_TIME>
</TraceTranslate>
- <TraceTranslate>
<AWB_CODE>112-04990930</AWB_CODE>
<FLIGHT_NO>CK261</FLIGHT_NO>
<FLIGHT_DATE>2013-10-11 23:44</FLIGHT_DATE>
<SHIMPENT_PIECE>2</SHIMPENT_PIECE>
<SHIMPENT_WEIGHT>333</SHIMPENT_WEIGHT>
<CARGO_CODE>RCS</CARGO_CODE>
<CARGO_NAME>货交航空公司指定货栈</CARGO_NAME>
<CARGO_ENNAME />
<TRACE_CODE>2521456</TRACE_CODE>
<TRACE_TIME>2013-10-11 20:37</TRACE_TIME>
<TRACE_LOCATION>上海浦东</TRACE_LOCATION>
<AIRPORT_DEP>上海浦东</AIRPORT_DEP>
<AIRPORT_LAND>桃源</AIRPORT_LAND>
<ORIGIN_AIRPORT>上海浦东</ORIGIN_AIRPORT>
<DESTINATION_AIRPORT>桃源</DESTINATION_AIRPORT>
<STARDARD_DATA>货交航空公司指定货栈(RCS):在上海浦东机场,航空公司于10-11 20:37 确认收到2件货物(重量为333KG)</STARDARD_DATA>
<TRACE_DATA>状态名称: 收货<BR/>航站名称: 上海浦东<BR/>航班号: <BR/>日期: 2013-10-11<BR/>时间: 20:37<BR/>状态描述: 从发货人或其代理 SZT 手中收到出港货物和文件<BR/>件数: 2<BR/>重量: 333</TRACE_DATA>
<OP_TIME>2013-11-15 13:47</OP_TIME>
</TraceTranslate>
</TraceTranslates>
</ResultData>
</ServiceResult>
想获取上面XML文件中<TRACE_DATA>与</TRACE_DATA>的内容,并循环输出,但提示错误,读取文件代码如下:
<%
set objXML=server.CreateObject("MSXML2.DOMDocument")
objXML.async=false
objXML.load(server.mappath("note.xml"))
set nodelist=objXML.documentElement.selectNodes("TraceTranslate")
for each xNode in nodelist
response.Write xNode.selectSingleNode("TRACE_DATA").text & " <br>"
next
%>
------解决方案--------------------
要显示<br/>的话, 用CDATA
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ServiceResult>
<CurrentPage>1</CurrentPage>
<PageSize>100</PageSize>
<ResultCount>11</ResultCount>
<ResultPages>1</ResultPages>
<ResultData>
<TraceTranslates>
<piece>2</piece>
<weight>333</weight>