|
Post by Mark Dunham on Apr 2, 2018 15:26:26 GMT -5
This is my example of parsing XML data. I also have a youtube video explaining what I am doing here youtu.be/xDkMfuCtFEc . The XML file I used in my example is attached. test.xml (444 B) 'THIS IS MY XML PARSER IT NEEDS MORE WORK 'BUT WILL WORK FOR NOW
'ARRAY ITEMS$(ID,NAME,WEIGHT) dim items$(100,3) idcount = 1 namecount = 1 weightcount = 1 id$ = "002"
open "test.xml" for input as #xml myXML$ = INPUT$(#xml, LOF(#xml)) close #xml
parse$ = UPPER$(myXML$)
tagpos = INSTR(parse$, "<ID>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+4, endpos - tagpos-4) items$(idcount,1) = tag$ idcount = idcount + 1 tagpos = INSTR(parse$,"<ID>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<NAME>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+6, endpos - tagpos-6) items$(namecount,2) = tag$ namecount = namecount + 1 tagpos = INSTR(parse$,"<NAME>",endpos)'NEEDED TO EXIT LOOP wend
tagpos = INSTR(parse$, "<WEIGHT>") while tagpos > 0 endpos = INSTR(parse$, "</", tagpos) tag$ = MID$(myXML$, tagpos+8, endpos - tagpos-8) items$(weightcount,3) = tag$ weightcount = weightcount + 1 tagpos = INSTR(parse$,"<WEIGHT>",endpos)'NEEDED TO EXIT LOOP wend
'PRINT A SPECIFIC ITEMS NAME for x = 1 to idcount - 1 if items$(x,1) = id$ then print items$(x,2) next x
'PRINT ALL ITEMS IN A NICE FORMAT print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:" for i = 1 to idcount - 1 print items$(i,1), items$(i,2), items$(i,3) next i
end
|
|