asp classic - Issue with XML / SelectNodes using ASP VBScript -
got issue displaying information xml. think has selecting correct node (company name). need fresh opinion... got feeling overlooking simple. code 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;
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 response.write(nodecount) each node in nodelist response.write(node.text & "<br>") next else response.write("error parsing results") end if set xmldom = nothing
results: nodecount = 0
thanks
your xml file uses namespaces. 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 default namespace http://xmlgw.companieshouse.gov.uk/v1-0/schema
. unless node using explicit namespace (e.g. <xsi:something>
) default namespace used, , must define , use default namespace in code well. 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
Comments
Post a Comment