ebay and xml default namespace

today i got a xml document from a customer who want to implement some ebay webservice. This document uses a default namespace. Partial goal is to get the amount of categorys in categorycount

- <GetSuggestedCategoriesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <Timestamp>2006-08-23T10:13:19.302Z</Timestamp>
 .....
  <CategoryCount>10</CategoryCount>
  </GetSuggestedCategoriesResponse>


when you try a simple VBScript sample using MSXML parser,  its no problem to select the value of a node

Dim xdoc As New DOMDocument
xdoc.Load "c:\call.xml"
MsgBox xdoc.SelectSingleNode("//CategoryCount").Text

 

If you try same with .NET XML classes it fails. Node contains nothing. The problem can be solved by namespacemanager. I am not shure why a fake namespace (ebay) is needed.

Dim api As New XmlDocument
api.Load("c:\call.xml")
Dim nspmgr As XmlNamespaceManager = New XmlNamespaceManager(api.NameTable)
nspmgr.AddNamespace("ebay", "urn:ebay:apis:eBLBaseComponents")
CategoryCount = api.SelectSingleNode("//ebay:CategoryCount", nspmgr).InnerText

hope this helps

Published Wednesday, August 23, 2006 2:56 PM by preishuber

Comments

# re: ebay and xml default namespace

Sunday, January 28, 2007 6:15 PM by Hayk

Great post!  Your suggestion worked for me.  Thank you.

Leave a Comment

(required) 
(required) 
(optional)
(required)