在经典 ASP 中对 XML 数据进行排序 [英] Sort XML data in classic ASP

查看:20
本文介绍了在经典 ASP 中对 XML 数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在xml下面排序,基于成人和儿童(我需要以成人和儿童为常数):

<HotelDetails><酒店><房间><房间><房间名>单身</房间名><价格>100</价格><成人>1</成人><孩子>0</孩子></房间></房间><房间><房间><房间名>单身</房间名><价格>150</价格><成人>1</成人><孩子>0</孩子></房间></房间><房间><房间><roomname>双人间</roomname><价格>200</价格><成人>2</成人><孩子>1</孩子></房间></房间></酒店></酒店详情>

给予:

<上一页>酒店 :单100,双200,总共 300 个单150,双200,总共 350 个

我尝试使用下面的代码进行排序,但它就像常量(不同的数据).任何人都知道使用下面的代码对 XML 进行排序?

<%@ Language="VBScript" CodePage="65001"%><%Response.ContentType = "文本/纯文本;字符集 = UTF-8"暗淡的文档设置 doc = Server.CreateObject("Msxml2.DOMDocument.3.0")doc.async = False如果 doc.load(Server.MapPath("ee.xml")) 那么doc.setProperty "SelectionLanguage", "XPath"暗淡 xpathxpath = "HotelDetails/hotel/rooms[not(room/Adult=previous-sibling::rooms/room/Adult)]/room/Adult"对于 doc.selectNodes(xpath) 中的每个成人Response.Write "Hotel" &VbCrLfResponse.Write Adult.ChildNodes.Item(0).Text &VbCrLf下一个别的Response.Write doc.parseError.reason万一%>

我该怎么做?

解决方案

另一种可能是使用 ADODB Disconnected Recordset,并使用 ADODB 工具进行排序和提取.

一个好的起点(代码在 VB 中):

  • 如何从 XML 获取 ADO 记录集

    Dim oStream As ADODB.Stream设置 oStream = New ADODB.StreamoStream.OpenoStream.WriteText sXML '将 XML 字符串提供给 ADO 流oStream.Position = 0 '将流位置设置为开始将 oRecordset 调暗为 ADODB.Recordset设置 oRecordset = New ADODB.RecordsetoRecordset.Open oStream '从流中打开一个记录集oStream.Close设置 oStream = 无Set RecordsetFromXMLString = oRecordset '返回记录集设置 oRecordset = 无

I want to sort below xml, Based on the Adult and child ( i need to take Adult and child as constant):

<HotelDetails>
  <hotel>
    <rooms>
      <room>
        <roomname>Single</roomname> 
        <Price>100</Price> 
        <Adult>1</Adult> 
        <child>0</child> 
      </room>
    </rooms>
    <rooms>
      <room>
        <roomname>Single</roomname> 
        <Price>150</Price> 
        <Adult>1</Adult> 
        <child>0</child> 
      </room>
    </rooms>
    <rooms>
      <room>
        <roomname>Double</roomname> 
        <Price>200</Price> 
        <Adult>2</Adult> 
        <child>1</child> 
      </room>
    </rooms>   
  </hotel>
</HotelDetails>

to give:

Hotel :   
Single-100,
Double-200,
Total 300

Single-150,
Double-200,
Total 350

I try to sort with below code, but it comes like constant (distinct data). Anyone have an idea to sort above XML use something like below code?

<%@ Language="VBScript" CodePage="65001"%>  
<%  
Response.ContentType = "text/plain; charset=UTF-8"  

Dim doc   
Set doc = Server.CreateObject("Msxml2.DOMDocument.3.0") 
doc.async = False  

If doc.load(Server.MapPath("ee.xml")) Then   
  doc.setProperty "SelectionLanguage", "XPath"

  Dim xpath
  xpath = "HotelDetails/hotel/rooms[not(room/Adult= preceding-sibling::rooms/room/Adult)]/room/Adult"

  For Each Adult in doc.selectNodes(xpath) 
    Response.Write "Hotel" & VbCrLf
    Response.Write Adult.ChildNodes.Item(0).Text & VbCrLf  
  Next
Else   
  Response.Write doc.parseError.reason   
End If 
%>  

How can I do this?

解决方案

Another possibility is to use an ADODB Disconnected Recordset, and use the ADODB tools for sorting and extracting.

A good place to start (code is in VB):

  • How To Obtain an ADO Recordset from XML

    Dim oStream As ADODB.Stream
    Set oStream = New ADODB.Stream
    
    oStream.Open
    oStream.WriteText sXML   'Give the XML string to the ADO Stream
    
    oStream.Position = 0    'Set the stream position to the start
    
    Dim oRecordset As ADODB.Recordset
    Set oRecordset = New ADODB.Recordset
    
    oRecordset.Open oStream    'Open a recordset from the stream
    
    oStream.Close
    Set oStream = Nothing
    
    Set RecordsetFromXMLString = oRecordset  'Return the recordset
    
    Set oRecordset = Nothing
    

这篇关于在经典 ASP 中对 XML 数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆