开发者

How sort xml by distinct data using classic asp?

开发者 https://www.devze.com 2022-12-14 09:09 出处:网络
this is my xml <XMLResponse> <Product> <Items> <ID>AA</ID> </Items> <Items>

this is my xml

<XMLResponse>
<Product>
<Items>
<ID>AA</ID>
</Items>
<Items>
<ID>BB</ID>
</Items>
<Items>
<ID>CC</ID>
</Items>
<Items>
<ID>AA</ID>
</Items>
<Items>
<ID>AA</ID>
</Items>
<Items>
<ID>BB</ID>
</Items>
</Product>
</XMLResponse>

this is the code i using in my classic asp

<%
Res开发者_如何学运维ponse.ContentType = "text/plain; charset=UTF-8"  

Dim xd3   
Set xd3 = Server.CreateObject("Msxml2.DOMDocument.3.0")   
xd3.async = False  
xd3.load(Server.MapPath("01.xml"))
For Each item In xd3.selectNodes("/XMLResponse/Product/Items[not(/ID=preceding-sibling:Product/Items/ID)]/ID")
response.write item.getElementsByTagName("items").item(0).getElementsByTagName("ID").item(0).text
next
%>

But the about asp code is not working fine

I need output like this with distinct ID's

ID: AA ID: BB ID: CC


ive found its hard to get the path of the select nodes just right... you may use an xml explorer that outputs the path (nice xml explorer xmlexplorer.codeplex.com/) then other thing you may consider is traversing the tree with

    Set entitys = xmlDOM.getElementsByTagName("items")
for i = 0 to entitys.length - 1
%><%=entitys(i).text%><%=entitys(i).getAttribute("source")%>
<%
next

that will pull the text of the node or any attributes (looks like you dont have any yet)

also looks at the MSDN XML DOM msdn.microsoft.com/en-us/library/ms757828(VS.85).aspx to see how to get first child or enumerate children

i dont know if its bad to ask but im just starting and need points so i can add links :) hope i helped...

0

精彩评论

暂无评论...
验证码 换一张
取 消