Solved

Select XML node with Namespaces using Classic ASP

Posted on 2013-10-22
2
861 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now