发行使用ASP VBScript的XML /的SelectNodes [英] Issue with XML / SelectNodes using ASP VBScript

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

问题描述

GOT上显示从XML信息的问题。我认为这是与选择正确的节点(公司名称)。需要新鲜的意见了......有一种感觉,我可能俯瞰很简单的东西。 code如下:

Got an issue displaying information from XML. I think it has something to do with selecting the correct Node (Company Name). Need a fresh opinion... got a feeling I am probably overlooking something really simple. Code as follows

XML

<GovTalkMessage>
    <EnvelopeVersion>1.0</EnvelopeVersion>
    <Header>
        <MessageDetails>
            <Class>CompanyDetails</Class>
            <Qualifier>response</Qualifier>
            <TransactionID>9999999999999</TransactionID>
            <GatewayTest>TRUE</GatewayTest>
            <GatewayTimestamp>2013-09-24T17:51:41-00:00</GatewayTimestamp>
        </MessageDetails>
        <SenderDetails>
            <IDAuthentication>
                <SenderID>******</SenderID>
                <Authentication>
                    <Method>CHMD5</Method>
                    <Value></Value>
                </Authentication>
            </IDAuthentication>
            <EmailAddress>rte@rrfsolicitors.com</EmailAddress>
        </SenderDetails>
    </Header>
    <GovTalkDetails>
        <Keys/>
    </GovTalkDetails>
    <Body>
        <CompanyDetails>
            <CompanyName>MILLENNIUM STADIUM PLC</CompanyName>
            <CompanyNumber>03176906</CompanyNumber>
            <RegAddress>
                <AddressLine>MILLENNIUM STADIUM</AddressLine>
                <AddressLine>WESTGATE STREET</AddressLine>
                <AddressLine>CARDIFF</AddressLine>
                <AddressLine>CF10 1NS</AddressLine>
            </RegAddress>
        </CompanyDetails>
    </Body>
</GovTalkMessage>

ASP code;

ASP Code;

Set XMLDom = CreateObject("MSXML2.DomDocument.6.0")
XMLDom.async = false
XMLDom.LoadXML (theXML)

theNode = "/GovTalkMessage/Body/CompanyDetails"

Set NodeList = XMLDom.SelectNodes(theNode)
nodeCount = XMLDom.SelectNodes(theNode).length  
if XMLDom.parseerror = 0 then
    Response.Write(nodeCount)
    For Each Node in NodeList 
        response.write(Node.text & "<br>")
    Next
else
    response.Write("Error Parsing Results")
end if
Set XMLDom = Nothing

结果:
nodeCount = 0

Results: nodeCount = 0

感谢

推荐答案

您的XML文件使用的命名空间。节点

Your XML file uses namespaces. The node

<CompanyDetails xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema
     http://xmlgw.companieshouse.gov.uk/v1-0/schema/CompanyDetails-v2-1.xsd">

定义了一个默认的命名空间 http://xmlgw.companieshouse.gov.uk/v1-0/schema 。除非一个节点使用一个明确的命名空间(如&LT; XSI:东西&GT; )的默认命名空间使用,必须定义并使用默认的命名空间在code作为好。像这样的东西应该工作:

defines a default namespace http://xmlgw.companieshouse.gov.uk/v1-0/schema. Unless a node is using an explicit namespace (e.g. <xsi:Something>) that default namespace is used, and you must define and use that default namespace in your code as well. Something like this should work:

XMLDom.setProperty "SelectionNamespaces" _
  , "xmlns:ns='http://xmlgw.companieshouse.gov.uk/v1-0/schema'"

theNode = "//ns:CompanyDetails"
Set NodeList = XMLDom.SelectNodes(theNode)
nodeCount = NodeList.Length

WScript.Echo nodeCount

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

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