login about faq

I've been pulling my hair out trying to figure out how to parse the XML code below in VB6. I need to be able to reference the content by it's tag name. For example I need to be able to pluck the content by it's element name e.g. "Album" and have it return the content "Face Up in the Rain." Preferably without having to do any iteration. Example strAlbum = XML.someMethodByTagName("Album") I've been able to reference and obtain the content by using an index i.e. strAlbum = XML.GetChildContentByIndex(n), but I need to be able to use the tag name because the order and number of the elements might change. Also, please note there are two references to "Status" and one element named "Name."

 <Response Status="OK">
   <Item Name="ZoneID">0</Item>
   <Item Name="State">2</Item>
   <Item Name="FileKey">305718</Item>
   <Item Name="Artist">Michael Tomlinson</Item>
   <Item Name="Album">Face Up in the Rain</Item>
   <Item Name="Name">The Way We're Going</Item>
   <Item Name="Status">Playing</Item>

Any insight/help would be greatly appreciated.

p.s. I'm woking in VB6, not C.

asked May 07 '15 at 12:16

avpman's gravatar image



answered May 07 '15 at 13:53

chilkat's gravatar image

chilkat ♦♦

Thanks for your significant efforts! Works almost perfect. But it won't return the content of the "Status" located in the last line of the XML - see below. I also need to get the content of the "Status" in the Response in the first line of the XML <Response Status="OK">

Last element "Status"

Set xItem = xml.GetChildWithAttr("Item", "Name", "Status")

xItem evals to nothing in the preceding line

As always, any ideas would be greatly appreciated.

(May 07 '15 at 15:59) avpman

Using, it worked for me after changing the success variable Boolean declaration with Long. Are you using the latest version of the library?

(May 07 '15 at 20:42) jpbro ♦

Thank you! I installed and I can now get the Status in the last line of the XML - "Playing." But how do I get the Status "OK" from the first line of the XML? p.s. I think above you meant the "success" variable, not status?

(May 08 '15 at 16:32) avpman

Calling xml.GetAttributeValue(0) will return "OK"

(May 09 '15 at 11:03) jpbro ♦

Right, that's a good workaround. But doing it that way was part of the original question, how do I reference it by the tag name and not by the index? Is this just an uncommon (screwy) XML format?

(May 09 '15 at 11:19) avpman

Sorry, I didn't actually read your initial question, I just tooka look at the example code and tried it out.

Is the Response tag always the root? If so you could try: xml.GetRoot.GetAttrValue("Status")

(May 09 '15 at 12:01) jpbro ♦

Yes, it's always first. With some commands sent to the server it is the ONLY thing returned (along with the XML declaration.) I.E. <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <Response Status="OK"/>

(May 09 '15 at 13:52) avpman

Works perfectly, even with the single element response! Thank you for all your help and especially your patience.

(May 09 '15 at 14:19) avpman
showing 5 of 8 show all
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: May 07 '15 at 12:16

Seen: 3,227 times

Last updated: May 09 '15 at 14:19

powered by OSQA