在传统的ASP排序XML数据 [英] Sort XML data in classic ASP

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

问题描述

我要排序如下基于XML的成人和儿童(我需要成人和儿童为常数):

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>

放弃:


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

Single-150,
Double-200,
Total 350

我试着用下面code进行排序,但说到像常数(不同的数据)。任何人都有一个想法整理上面的XML使用类似下面code?

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?

推荐答案

另一种可能是使用ADODB断开记录,并使用ADODB工具进行分拣和提取。

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

有一个良好的开端(code是在VB中):

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

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天全站免登陆