使用传统的ASP XML的selectNodes [英] XML selectNodes using Classic ASP

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

问题描述

这就是让我难住了,但可能是非常简单的...

XML problem that's got me stumped, but is probably very simple...

该XML是这样的:

    <header>
    <createdOn>16 Sep 2009</createdOn>
    <createdBy>Jez</createdBy>
</header>
<agents>
    <agent>
            <agentDetails>
                    <agentName>text</agentName>
                    <agentTelephone>text</agentTelephone>
            </agentDetails>
            <properties>
                    <property>
                            <propertyid>number</propertyid>
                            <address>
                                    <number>1</number>
                                    <street>High St</street>
                                    <postcode></postcode>
                                    <country>UK</country>
                            </address>
                            <price>
                                    <category>text</category>
                                    <price>number</price>
                                    <reference>text</reference>
                            </price>
                            <description>
                                    <propertyType>House</propertyType>
                                    <bedrooms>2</bedrooms>
                                    <bathrooms>1</bathrooms>
                                    <sleeps>
                                    <briefDescription>text</briefDescription>
                                    <addDescription>long-text</addDescription>
                                    <floorSize>
                                            <size>80</size>
                                            <type>sq. mt</type>
                                    </floorSize>
                                    <bullets>
                                            <bullet>No Of Bedrooms : 2</bullet>
                                            <bullet>Condition : Habitable</bullet>
                                            <bullet>Land Size (M2): 2,000</bullet>
                                    </bullets>
                            </description>
                            <images>
                                    <image>
                                            <thumbnail>URL</thumbnail>
                                            <image>URL</image>
                                            <alttext></alttext>
                                    </image>
                                    <image>
                                            <thumbnail>URL</thumbnail>
                                            <image>URL</image>
                                            <alttext></alttext>
                                    </image>
                            </images>
                            <links>
                                    <link>
                                            <type>text</type>
                                            <url>url</url>
                                    </link>
                                    <link>
                                            <type>text</type>
                                            <url>url</url>
                                    </link>
                            </links>
                    </property>
            </properties>
    </agent>
 </agents>

而code我想用的是:

And the code I would like to use is:

    Set NodeList = objXML.documentElement.selectNodes("agents/agent/properties/property")
For Each Node In NodeList
    'I want to be able to extract distinct fields here...
    response.write Node.selectSingleNode("address/street") & "<br/>"
    response.write Node.selectSingleNode("description/briefDescription") & "<br/>"
Next

不过,我不知道怎么办。

But, I don't know how.

此外,这可能是一个问题,例如,&LT;图片&GT; &LT;链接&GT; 标记。

ALso, this could be a problem with, for example, the <images> and <links> tags.

建议好吗?

推荐答案

首先,你已经发布的XML的例子是无效的。它缺乏一个根元素(或有多个根元素,这取决于你的观点)。此外,&LT;睡&GT; 元素是永远不会关闭。我觉得这可能是输入错误在你的榜样?

First, the XML example you've posted is invalid. It lacks a root element (or has multiple root elements, depending on your point of view). Also, the <sleeps> element is never closed. I think these might be typos in your example?

我不知道你所说的意思:我希望能够在这里提取不同的领域。你可以给输出的例子,你是后?

I'm not sure what you mean by "I want to be able to extract distinct fields here." Can you give an example of the output that you are after?

没有更多的信息,我可以建议尝试这样一些变化:

Without more information, I can suggest trying some variation of this:

Dim NodeList, Node, SubNode
'' # Note: Replace [root] with your actual root level element
Set NodeList = objXML.documentElement.selectNodes("/[root]/agents/agent/properties/property")
For Each Node In NodeList
    '' # Do something useful... ?? Distinct fields??
    Set Node = Node.selectSingleNode("address/street/text()")
    If Not Node Is Nothing Then
        Response.Write Server.HTMLEncode(Node.nodeValue) & "<br />"
    End If
Next

这是否帮助?

这篇关于使用传统的ASP XML的selectNodes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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