Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split Data and Display in Listbox 1

Status
Not open for further replies.

M626

Programmer
Mar 13, 2002
299
Ok,

Here is what I was try to accomplish with getting the number of time "<" appears in a string. I am reading in XML data comming in on port 9600 using Winsock and trying to grab and display the data between <KEYWORD> and </KEYWORD>. The data appears to come in as one contionious line with the carage returns showing up at the end of the line.

'I tried.

For i = 1 To Len(Data)
If Mid$(Data, i, 1) = "<" Then count = count + 1
If count = 10 Then
keyWordHolder = Mid(Data, 2, 17)
List1.AddItem keyWordHolder
End If
Next

also tried

If InStr(1, (Mid(Data, 2, 7)), "KEYWORD", vbBinaryCompare) Then
keyWordHolder = Mid(Data, 10, 14)
List1.AddItem keyWordHolder
End If

but becasue it's one continious line, it doesn't work.

I though if I did

For i = 1 To Len(Data)
If Mid$(Data, i, 1) = "<" Then count = count + 1

If count = 8 Then

keyWordHolder = Mid(Data, 2, 17)
List1.AddItem keyWordHolder
Next

but that doesn't work but maybe if I used

Mid(data, x, y)
x = lenght to 8th "<" found
Y = lenght to 9th "<" found

I am getting frustrated with this, any help would be greatly appreciated.

thanks,

SAMPLE DATA
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE MAJORLEAGUEDSTAT SYSTEM "Xmldtds/Major League
Baseball/MAJORLEAGUEDSTAT.dtd">
<MAJORLEAGUEDSTAT selectorcode="DSMLB" league="BBA" category="STAT">
<STORYNUMBER>9000-NON-EVENT-MESSAGE-X</STORYNUMBER>
<SELECTORCODE>DSMLB</SELECTORCODE>
<KEYWORD>BC-BBA-STAT-AL1DAYCENT</KEYWORD>
<VERSION> </VERSION>
<DATE>10-04</DATE>
<WORDCOUNT>0000</WORDCOUNT>
<DATETIME>st 10-04-04 19:50 et</DATETIME>
<HRECORD>
<H_RECTYPE>H</H_RECTYPE>
<H_RECNUMBER>0000001</H_RECNUMBER>
<H_FEEDTYPE>MLBD</H_FEEDTYPE>
<H_LEAGUE>AL</H_LEAGUE>
<H_DIVISION>CENT</H_DIVISION>
<H_SEASON>R</H_SEASON>
<H_GAMEDATE>20041003</H_GAMEDATE>
<H_CREATEDATE>20041004</H_CREATEDATE>
<H_CREATETIME>195059</H_CREATETIME>
</HRECORD>
</MAJORLEAGUEDSTAT>
 
use split with "KEYWORD>" the seperator
item 1 (index=0) of your result-array holds then
start-keyword, item 2 the rest
now split item 2 ( or use instr) with "<" to strip the end-tag from your string and what you've got is the tag's value in between.
 
alternatively use
Code:
Dim iStartPos As Integer, iEndPos As Integer
iStartPos = InStr(1, Data, "<KEYWORD>")
iEndPos = InStr(1, Data, "</KEYWORD>")
Debug.Print Mid(Data, iStartPos + 9, iEndPos - (iStartPos + 9))

"I'm living so far beyond my income that we may almost be said to be living apart
 
Try doing a forum search on 'xml' and 'dom'. The Microsoft Document Object Model is designed to parse XML without the hassle

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
johnwm
I thought about using that but what impact will it have if the data stream includes reference to a dtd, which it doesnt necessarily have access to?
Does this affect the DOM?

"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top