Solved

Select XML node with Namespaces using Classic ASP

Posted on 2013-10-22
2
887 Views
Last Modified: 2013-10-23
I have an XML file that uses namespaces. I need to access these nodes using classic ASP. I've done this before on a different XML file that did not use namespaces using something like:

For Each wNode In xmlDoc2.SelectNodes("/inv-balance/item") 

Open in new window


Apparently, that won't work this time since the XML uses namespaces.

Here is the XML file I'm working with. How do I access the nodes using classic ASP and namespaces?

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getInventoryQtyTransitDaysResponse xmlns:ns2="http://impl.webservice.integration.sanmar.com/">
<return>
<errorOccurred>false</errorOccurred>
<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>XS</size>
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>69</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>


<listResponse xsi:type="ns2:item" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<style>ST350</style>
<color>Iron Grey</color>
<size>S</size> 
<inventoryKey></inventoryKey>
<sizeIndex></sizeIndex>
<shipToPostalCode>99202</shipToPostalCode>
<quantity>500</quantity>
<daysInTransit>1</daysInTransit>
</listResponse>



<message>Request fulfilled successfully</message>
</return>
</ns2:getInventoryQtyTransitDaysResponse>
</S:Body>
</S:Envelope>

Open in new window


My ASP code so far:

set xmlDoc2 = createObject("MSXML2.DOMDocument")
xmlDoc2.async = False
xmlDoc2.setProperty "ServerHTTPRequest", true
xmlDoc2.load("http://www.sportsupplygroup.com/Sanmar/transit.xml")
For Each oNode In xmlDoc2.SelectNodes(?????)

Open in new window

0
Comment
Question by:P-Daddy
2 Comments
 

Author Comment

by:P-Daddy
ID: 39592454
I need to access the size node.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39593589
first note that (//size) will work since <size> is NOT in a namespace
(there is no default namespace declared)

for the nodes inside namespaces, you need to bind a namespace prefix

(assuming the selectionLanguage is set to XPath:

xmlDoc2.setProperty "SelectionNamespaces", "xmlns:foo='http://impl.webservice.integration.sanmar.com/'"

will allow you to select the nodes //foo:getInventoryQtyTransitDaysResponse

note that I changed the prefix on purpos, it is not the prefix that is important, but the namespace uri it is bound to
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XSL-FO - show results in 2 columns 5 32
XML to SQL Table using c# 5 64
XSLT XML 4 19
Connecting to multiple databases to create a Dashboard 5 25
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question