在经典ASP中对XML数据进行排序

时间:2022-07-02 05:19:46

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

我想在xml下面排序,基于Adult和child(我需要将Adult和child视为常量):

<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?

我尝试使用下面的代码进行排序,但它就像常量(不同的数据)。任何人都有想法在XML之上使用类似下面代码的东西?

<%@ 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?

我怎样才能做到这一点?

2 个解决方案

#1


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

另一种可能性是使用ADODB断开连接的记录集,并使用ADODB工具进行排序和提取。

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

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

  • How To Obtain an ADO Recordset from XML

    如何从XML获取ADO记录集

    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
    

#2


Would this be helpful http://www.developer.com/xml/article.php/1560361 , It shows how to use XSL transformation to output XML sorted in the form of HTML, But I think you can modify XSL output to be XML (<xsl:output>)

这将是有用的http://www.developer.com/xml/article.php/1560361,它显示了如何使用XSL转换输出以HTML形式排序的XML,但我认为您可以将XSL输出修改为XML (的 ) 输出>

If these records coming from SQL Server, It is much easier to output them sorted already.. Are you trying to do caching??

如果这些记录来自SQL Server,那么输出它们已经很容易排序了..你是否想要进行缓存?

If you trying to do caching , check my post: http://www.moretechtips.net/2008/11/object-oriented-data-caching-for.html

如果您尝试进行缓存,请查看我的帖子:http://www.moretechtips.net/2008/11/object-oriented-data-caching-for.html

#1


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

另一种可能性是使用ADODB断开连接的记录集,并使用ADODB工具进行排序和提取。

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

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

  • How To Obtain an ADO Recordset from XML

    如何从XML获取ADO记录集

    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
    

#2


Would this be helpful http://www.developer.com/xml/article.php/1560361 , It shows how to use XSL transformation to output XML sorted in the form of HTML, But I think you can modify XSL output to be XML (<xsl:output>)

这将是有用的http://www.developer.com/xml/article.php/1560361,它显示了如何使用XSL转换输出以HTML形式排序的XML,但我认为您可以将XSL输出修改为XML (的 ) 输出>

If these records coming from SQL Server, It is much easier to output them sorted already.. Are you trying to do caching??

如果这些记录来自SQL Server,那么输出它们已经很容易排序了..你是否想要进行缓存?

If you trying to do caching , check my post: http://www.moretechtips.net/2008/11/object-oriented-data-caching-for.html

如果您尝试进行缓存,请查看我的帖子:http://www.moretechtips.net/2008/11/object-oriented-data-caching-for.html