Hi Tom,
In VB6 you have the XML DOM objects. Include a reference to “Microsoft XML v4.0” in your project to use it.
There are three basic operations you’ll need to get data out from the XML document:
1. Create an XML Document object
Dim objXML As New MSXML2.DOMDocument
2. Load your XML document into the object, passing its location on disk or URL
objXML.Async = false
objXML.Load( “c:\users\BillGates\Documents\competition.xml” )
3. Select the nodes you want to use with XPath and the method SelectNodes
Dim NodeList as XMLDOMNodeList
Set NodeList = objXML.SelectNodes( “/ArrayOfCompetition/Competition/EventName” )
(Note to readers using better programming languages: Did you notice that there is no need to bother with namespace handling? Oh! Those old good times :D ).
This will give you a collection of all the EventName elements in every Competition element in your document.
The you can loop every resulting node with a For .. in … do loop in VB, like this:
Dim xNode As MSXML.IXMLDOMNode
For Each xNode In NodeList
Print xNode.text
Is a good idea to add error handling. Take a look to this article from Microsoft to learn how to deal with XML, including error handling: http://msdn.microsoft.com/en-us/library/aa468547.aspx
The key to be proficient with XML is XPath. Somebody else can recommend you a “Good” resource for learning it (Sorry me not… I learned XPath in w3schools :D ).
Hope this helps,
- Bill
De: Tom Martin [mailto:tomdmartin@gmail.com]
Enviado el: viernes, 13 de junio de 2014 1:06 p. m.
Para: xml-dev@lists.xml.org
Asunto: [xml-dev] need help / insight on parsing some xml with vb6
Hey,
I'm working on a project and need to parse some xml code using vb6.
The xml file as around 50 "sections" in it that I need to examine and pull out certain info...
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfCompetition xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Web.Controllers">
- <Competition>
<ChiefJudge />
<CompetitionGuid>72a399f8-480c-4743-9c14-4357a77582ce</CompetitionGuid>
<CompetitionName />
<Date>2014-06-26T09:00:00</Date>
<EventName>Southwest Corps Connection</EventName>
<GroupTypeID>4</GroupTypeID>
<IsCurrentSeason>true</IsCurrentSeason>
<Location>Mesa AZ</Location>
<OrgCompetitionID>0</OrgCompetitionID>
<PerformancesUrl>https://api.competitionsuite.com/2013-02/Performances/?c=72a399f8-480c-4743-9c14-4357a77582ce</PerformancesUrl>
<RecapReleased>false</RecapReleased>
<RecapUrl>http://recaps.competitionsuite.com/72a399f8-480c-4743-9c14-4357a77582ce.htm</RecapUrl>
<SeasonGuid>348fac28-d10c-47e5-8753-802512df9904</SeasonGuid>
<SeasonName>2014</SeasonName>
</Competition>
..........
</ArrayOfCompetition>
What I need to do is parse all of this out into some combo boxes. Not sure where to start...
Thoughts?
Thanks. Tom