Dan*_*Boy 2 xml vbscript asp-classic
显示 XML 信息时遇到问题。我认为这与选择正确的节点(公司名称)有关。需要新的意见...有一种感觉,我可能忽略了一些非常简单的事情。代码如下。
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>
Run Code Online (Sandbox Code Playgroud)
ASP 代码:
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
Run Code Online (Sandbox Code Playgroud)
结果:节点计数 = 0
您的 XML 文件使用命名空间。节点
<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">Run Code Online (Sandbox Code Playgroud)
定义一个默认的命名空间http://xmlgw.companieshouse.gov.uk/v1-0/schema。除非节点使用显式命名空间(例如<xsi:Something>),否则将使用默认命名空间,并且您也必须在代码中定义和使用该默认命名空间。像这样的东西应该有效:
<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">Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6006 次 |
| 最近记录: |