如何使用带有xpath的经典asp(vbscript)对xml数据进行排序?

时间:2022-06-17 00:26:28

    <rooms>     
        <room>
            <roomname>Single</roomname>
            <roomid>1</roomid>
            <Price>100</Price>
            <Adult>1</Adult>
            <child>0</child>
        </room> 
    </rooms>


    <rooms>
        <room>
            <roomname>Double</roomname>
            <roomid>2</roomid>
            <Price>200</Price>
            <Adult>2</Adult>
            <child>1</child>
        </room>
    </rooms>

    <rooms>
        <room>
            <roomname>Single</roomname>
            <roomid>3</roomid>
            <Price>150</Price>
            <Adult>1</Adult>
            <child>0</child>
        </room>
    </rooms>

</hotel>

i need out put like this ...( use vbscript in classic asp )

我需要像这样出去……(在经典asp中使用vbscript)

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

酒店:单100,双200,共300家

Single-150, Double-200, Total 350

单- 150,双- 200,总计350

concept is: 1. customer need 2 rooms, 1st room 1 adult and 2nd room 2adults + 1child ( based on above xml) 2. customer he can choose up to max 4 rooms, each rooms max adult is 4 and max child is 2, for that each customer request xml is generated like this

概念是:1。客户需要2个房间,1个成人房,2个成人房+ 1个孩子(基于以上xml)客户可以选择最多4个房间,每个房间最大成人4个,最大儿童2个,因为每个客户请求xml都是这样生成的

for example: customer need 3 rooms, 1st room 1 adult, 2nd room 2 adult +1child and 3rd room 3adult , xml is like this (rooms is generated based on the availability)...

例如:客户需要3个房间,1个成人房,2个成人房+1个儿童房,3个成人房,xml是这样的(根据可用性生成房间)……

    <rooms>     
        <room>
            <roomname>Single</roomname>
            <roomid>1</roomid>
            <Price>100</Price>
            <Adult>1</Adult>
            <child>0</child>
        </room> 
    </rooms>


    <rooms>
        <room>
            <roomname>Double</roomname>
            <roomid>2</roomid>
            <Price>200</Price>
            <Adult>2</Adult>
            <child>1</child>
        </room>
    </rooms>

    <rooms>
        <room>
            <roomname>Single</roomname>
            <roomid>3</roomid>
            <Price>150</Price>
            <Adult>1</Adult>
            <child>0</child>
        </room>
    </rooms>

               <rooms>      
        <room>
            <roomname>Triple</roomname>
            <roomid>4</roomid>
            <Price>300</Price>
            <Adult>3</Adult>
            <child>0</child>
        </room> 
    </rooms>

</hotel>

in this cause out put i need like this

在这个事业中,我需要像这样

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

酒店:单100,双200,三300,共600家

Single-150, Double-200, Triple-300, Total 650

单150,双200,三300,总共650

I try to take out using vbscript, but some cause is accepted but some cause not

我尝试使用vbscript退出,但是有些原因是可以接受的,有些原因不是

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

for i= 1 to 3 '2 is noofrooms

adult1 ="1"
child1 ="0"
adult2 ="2"
child2 ="1"
adult3 ="3"
child3 ="0"
'adult4 ="4"
'child4 ="0"


for d=0 to 4 ' total nodes ( /rooms)

' this for 2 room cause
'ds ="(//HotelDetails/hotel/rooms/room[Adult='"&adult1&"' and child='"&child1&"'])["&i&"]|(//HotelDetails/hotel/rooms/room[Adult='"&adult2&"' and child='"&child2&"'])["&d&"]" 

' this for 3 room cause
ds ="(//HotelDetails/hotel/rooms/room[(Adult='"&adult1&"' and child='"&child1&"') ])["&i&"]|((//HotelDetails/hotel/rooms/room[(Adult='"&adult2&"' and child='"&child2&"')])|(//HotelDetails/hotel/rooms/room[(Adult='"&adult3&"' and child='"&child3&"')]))["&d&"]"


' this for 4 room cause
'ds ="(//HotelDetails/hotel/rooms/room[(Adult='"&adult1&"' and child='"&child1&"') ])["&i&"]|((//HotelDetails/hotel/rooms/room[(Adult='"&adult2&"' and child='"&child2&"')])|(//HotelDetails/hotel/rooms/room[(Adult='"&adult3&"' and child='"&child3&"')])|(//HotelDetails/hotel/rooms/room[(Adult='"&adult3&"' and child='"&child3&"')]))["&d&"]"



Set colNodes=doc.selectNodes (ds)
For Each objNode in colNodes

  response.write objNode.Text & VbCrLf 

Next

next


next

Else   
  Response.Write doc.parseError.reason   
End If

Plz help me to (take output) solve this problem thanks

Plz帮我解决这个问题,谢谢

1 个解决方案

#1


0  

Is this a repeat of: Sort XML data in classic ASP ?

这是重复的:在经典ASP中排序XML数据吗?

#1


0  

Is this a repeat of: Sort XML data in classic ASP ?

这是重复的:在经典ASP中排序XML数据吗?