Issue with XML / SelectNodes using ASP VBScript

后端 未结 2 728
[愿得一人]
[愿得一人] 2020-11-27 07:56

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 proba

相关标签:
2条回答
  • 2020-11-27 08:29

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

    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:

    uri = "http://xmlgw.companieshouse.gov.uk/v1-0/schema"
    XMLDom.setProperty "SelectionNamespaces", "xmlns:ns='" & uri & "'"
    
    theNode = "//ns:CompanyDetails"
    Set NodeList = XMLDom.SelectNodes(theNode)
    nodeCount = NodeList.Length
    
    WScript.Echo nodeCount
    
    0 讨论(0)
  • 2020-11-27 08:39

    If you want to obtain the node CompanyName, then try this:

    theNode = "/GovTalkMessage/Body/CompanyDetails/CompanyName"
    Response.Write (XMLDom.SelectSingleNode(theNode).xml)
    
    0 讨论(0)
提交回复
热议问题