PDA

View Full Version : MSXML2 - getElementsByTagName()



hoopz
12-08-2006, 06:38 PM
Hi, I'm pretty unfamiliar with XML, but I'm writing a VBA program in excel that uses the MSN Soap Library to retrieve XML object's from this database on the web. Then I need to extract info from these XML objects and distribute them into a worksheet. Basically, the first part of my code returns an IXMLDOMSelection object, let's call it objX.

objX has a bunch of child nodes containing the info I want to extract. I'm trying to use the method 'getElementsByTagName(Name As String)' to return nodes matching a particular tagname so that I can get the text from those nodes and put it in the correct place in my worksheet. The problem is, I can't get "getElementsByTagName" to work properly. I searched the internet, and found out that the following command should return all nodes in the object, which it does.
objX.getElementsByTagName("*")So when I look at the tagnames of these nodes and if, for example, the tagname of the 1st node is 'tag', the following command should return just that first node.
objX.getElementsByTagName("tag") However, this is not returning anything at all, and I'm completely baffled as to how to make it work.

Hopefully someone has some idea of what I'm talking about and can either help me out or tell me I'm going about this the wrong way. Thanks

Simon Lloyd
12-09-2006, 12:34 AM
Cross Posted http://www.excelforum.com/showthread.php?t=582871

Please follow this link and read it for an explanation of cross-posting
http://www.excelguru.ca/node/7

stanl
12-09-2006, 10:12 AM
the tagname of the 1st node is 'tag', the following command should return just that first node.

You should use the Item property - using something like
oXML.GetElementsByTagName("*").Item(1).NodeName should return "tag" in your case. Also, you might want to look into the thread on XML parsing in the Other forum on this board. Stan