vb.net 在 vb .NET 中读取和解析 XML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13219162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reading and Parsing XML in vb .NET
提问by Ayden Ramsden
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<HorseRacingCard>
<Meeting status="Dormant" id="51894" country="South Africa" course="Vaal" date="20121101">
<DrawAdvantage>Outside draws hold an advantage on the straight course.</DrawAdvantage>
<AdvancedGoing>Good</AdvancedGoing>
<Race trifecta="No" id="433065" date="20121101" time="1010+0000" raceType="Flat" trackType="Turf" handicap="No" class="" showcase="No" maxRunners="16">
<Title>Save The Date Sansui Summer Cup 1 December Maiden Plate</Title>
<AddedMoney currency="ZAR" amount="74996"/>
<PenaltyValue currency="ZAR" amount="51622"/>
<Prizes currency="ZAR">
<Prize position="1" amount="51622"/>
<Prize position="2" amount="14833"/>
<Prize position="3" amount="7410"/>
</Prizes>
<Eligibility type="3YO plus"/>
<Distance units="yards" value="1094" text="0m 4f 214y"/>
<LastWinner year="2011" noRace="No corresponding race"/>
<Horse id="1515186" name="Magic Of Rome" bred="SAF">
<Cloth number="1"/>
<Drawn stall="8"/>
<FormFigures figures="598793" type="FlatSix"/>
<LastRunDays type="Flat" days="21"/>
<Age years="5"/>
<Weight text="9 6" units="pounds" value="132"/>
<Trainer id="41207" name="Chris Erasmus" nationality="SAF"/>
<Owner name="Messrs Werner Kuhn & Tjaart Strydom"/>
<Jockey id="82671" name="J V'd Merwe"/>
<JockeyColours filename="20121101vaa101001.png" description="Yellow, purple epaulettes, armbands and cuffs, checked cap"/>
<Tackle type="Blinkers" count="21"/>
<Colour type="b"/>
<Sex type="g"/>
<Breeding type="Sire" name="Caesour" bred="USA" yearBorn="1990"/><Breeding type="Dam" name="Magic Filly" bred="AUS"/><Breeding type="DamSire" name="Bletchley Park" bred="IRE" yearBorn="1989"/>
<FoalDate date="20070815"/>
<ForecastPrice>
<Price numerator="14" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1632709" name="Enblazoned Star" bred="SAF">
<Cloth number="2"/>
<Drawn stall="9"/>
<FormFigures figures="306740" type="FlatSix"/>
<LastRunDays type="Flat" days="51"/>
<Age years="4"/>
<Weight text="9 6" units="pounds" value="132"/>
<Trainer id="41348" name="Leon Erasmus" nationality="SAF"/>
<Owner name="Mr L J & Mrs M J Erasmus"/>
<Jockey id="1144567" name="Wesley Marwing"><Allowance units="pounds" value="9"/></Jockey>
<JockeyColours filename="20121101vaa101002.png" description="Red, blue epaulettes and sleeves, red cap"/>
<Tackle type="Blinkers" count="14"/>
<Colour type="ch"/>
<Sex type="g"/>
<Breeding type="Sire" name="Bezrin" bred="USA" yearBorn="1999"/><Breeding type="Dam" name="Starbright" bred="SAF" yearBorn="1995"/><Breeding type="DamSire" name="Fluorescent Light" bred="USA"/>
<FoalDate date="20080926"/>
<ForecastPrice>
<Price numerator="14" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1736936" name="Mboweni" bred="SAF">
<Cloth number="3"/>
<Drawn stall="14"/>
<FormFigures figures="742234" type="FlatSix"/>
<LastRunDays type="Flat" days="21"/>
<RaceHistoryStat type="BeatenFavourite" value="2"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="41348" name="Leon Erasmus" nationality="SAF"/>
<Owner name="Mr F D A Menezes"/>
<Jockey id="21795" name="G Lerena"/>
<JockeyColours filename="20121101vaa101003.png" description="White, black and orange striped sleeves, orange cap"/>
<Colour type="b"/>
<Sex type="c"/>
<Breeding type="Sire" name="Lecture" bred="USA" yearBorn="1996"/><Breeding type="Dam" name="Ad Valorem" bred="SAF" yearBorn="2000"/><Breeding type="DamSire" name="Caesour" bred="USA" yearBorn="1990"/>
<FoalDate date="20090907"/>
<ForecastPrice>
<Price numerator="3" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1774005" name="Make My Majesty" bred="SAF">
<Cloth number="4"/>
<Drawn stall="4"/>
<FormFigures figures="878755" type="FlatSix"/>
<LastRunDays type="Flat" days="5"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="45437" name="Romeo Francis"/>
<Owner name="Mr R Francis"/>
<Jockey id="60482" name="Derreck David"/>
<JockeyColours filename="20121101vaa101004.png" description="Red, black chevrons and sleeves, red armbands and cap"/>
<Tackle type="Blinkers" count="5"/>
<Colour type="b"/>
<Sex type="c"/>
<Breeding type="Sire" name="The Sheik" bred="SAF" yearBorn="1996"/><Breeding type="Dam" name="Mamzelle Magique" bred="SAF" yearBorn="1999"/><Breeding type="DamSire" name="Badger Land" bred="USA"/>
<FoalDate date="20091102"/>
<ForecastPrice>
<Price numerator="14" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1806596" name="All The Ones" bred="SAF">
<Cloth number="5"/>
<Drawn stall="12"/>
<FormFigures figures="54" type="FlatSix"/>
<LastRunDays type="Flat" days="5"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="41151" name="Paul Matchett"/>
<Owner name="Messrs P J Magee & J J Van Niekerk"/>
<Jockey id="28125" name="R Simons"/>
<JockeyColours filename="20121101vaa101005.png" description="Red, silver stars"/>
<Colour type="b"/>
<Sex type="g"/>
<Breeding type="Sire" name="Carpocrates" bred="USA" yearBorn="2003"/><Breeding type="Dam" name="Kal Sufi" bred="SAF"/><Breeding type="DamSire" name="Al Mufti" bred="USA" yearBorn="1985"/>
<FoalDate date="20091111"/>
<ForecastPrice>
<Price numerator="4" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819715" name="Dis'llbetheday" bred="SAF">
<Cloth number="6"/>
<Drawn stall="7"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="41149" name="Roy Magner"/>
<Owner name="Mr & Mrs E Prinsloo & Messes A T & E T Joseph & Me"/>
<Jockey id="30057" name="G Wrogemann"/>
<JockeyColours filename="20121101vaa101006.png" description="Oyster grey, claret collar, cuffs and cap"/>
<Colour type="b"/>
<Sex type="g"/>
<Breeding type="Sire" name="Daylami" bred="IRE" yearBorn="1994"/><Breeding type="Dam" name="World Premiere" bred="SAF" yearBorn="1996"/><Breeding type="DamSire" name="Model Man" bred="SAF"/>
<FoalDate date="20091111"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819716" name="Inews" bred="SAF">
<Cloth number="7"/>
<Drawn stall="11"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="41207" name="Chris Erasmus" nationality="SAF"/>
<Owner name="Messrs Werner Kuhn & Tjaart Strydom"/>
<Jockey id="22000" name="S Veale"/>
<JockeyColours filename="20121101vaa101007.png" description="Yellow, purple epaulettes, armbands and cuffs, checked cap"/>
<Colour type="b"/>
<Sex type="c"/>
<Breeding type="Sire" name="Winter Romance" bred="UK" yearBorn="1993"/><Breeding type="Dam" name="Readallaboutit" bred="SAF"/><Breeding type="DamSire" name="Gallic League" bred="IRE"/>
<FoalDate date="20090915"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819717" name="Magic Lad" bred="SAF">
<Cloth number="8"/>
<Drawn stall="10"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="100130" name="Stanley M Ferreira"/>
<Owner name="Mr M J Nunes"/>
<Jockey id="28344" name="Menno Malherbe"/>
<JockeyColours filename="20121101vaa101008.png" description="Black, white maltese cross, black and white striped sleeves and cap"/>
<Colour type="ch"/>
<Sex type="c"/>
<Breeding type="Sire" name="Jallad" bred="USA" yearBorn="1988"/><Breeding type="Dam" name="Magic Filly" bred="AUS"/><Breeding type="DamSire" name="Bletchley Park" bred="IRE" yearBorn="1989"/>
<FoalDate date="20090921"/>
<ForecastPrice>
<Price numerator="10" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819718" name="Menacing" bred="SAF">
<Cloth number="9"/>
<Drawn stall="2"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="55813" name="Michael Nicholas Houdalakis" nationality="SAF"/>
<Owner name="Mr Colin Bird"/>
<Jockey id="28018" name="C Maujean"/>
<JockeyColours filename="20121101vaa101009.png" description="Black, red chevron, black sleeves, red cap"/>
<Colour type="ch"/>
<Sex type="g"/>
<Breeding type="Sire" name="Go Deputy" bred="USA" yearBorn="2000"/><Breeding type="Dam" name="Fearsome" bred="SAF" yearBorn="1997"/><Breeding type="DamSire" name="Centenary" bred="USA"/>
<FoalDate date="20090906"/>
<ForecastPrice>
<Price numerator="14" denominator="1"/>
</ForecastPrice>
</Horse>
</Race>
<Race trifecta="No" id="433066" date="20121101" time="1045+0000" raceType="Flat" trackType="Turf" handicap="No" class="" showcase="No" maxRunners="16">
<Title>All To Come Maiden Plate (F & M)</Title>
<AddedMoney currency="ZAR" amount="74996"/>
<PenaltyValue currency="ZAR" amount="51622"/>
<Prizes currency="ZAR">
<Prize position="1" amount="51622"/>
<Prize position="2" amount="14833"/>
<Prize position="3" amount="7410"/>
</Prizes>
<Eligibility type="3YO plus"/>
<Distance units="yards" value="1312" text="0m 5f 212y"/>
<LastWinner year="2011" noRace="No corresponding race"/>
<Horse id="1702450" name="Festive Interlude" bred="SAF">
<Cloth number="1"/>
<Drawn stall="3"/>
<FormFigures figures="272533" type="FlatSix"/>
<LastRunDays type="Flat" days="5"/>
<Age years="4"/>
<Weight text="9 6" units="pounds" value="132"/>
<Trainer id="15533" name="D Gray St John"/>
<Owner name="Mr St John D Gray"/>
<Jockey id="21795" name="G Lerena"/>
<JockeyColours filename="20121101vaa104501.png" description="Green, white rings, quartered cap"/>
<Tackle type="Blinkers" count="10"/>
<Colour type="b"/>
<Sex type="f"/>
<Breeding type="Sire" name="Sarge" bred="SAF" yearBorn="1999"/><Breeding type="Dam" name="Festive Ways" bred="SAF" yearBorn="2000"/><Breeding type="DamSire" name="Model Man" bred="SAF"/>
<FoalDate date="20080920"/>
<ForecastPrice>
<Price numerator="5" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1682817" name="Snow Go" bred="SAF">
<Cloth number="2"/>
<Drawn stall="12"/>
<FormFigures figures="789850" type="FlatSix"/>
<LastRunDays type="Flat" days="28"/>
<Age years="4"/>
<Weight text="9 6" units="pounds" value="132"/>
<Trainer id="41198" name="Dominic Zaki"/>
<Owner name="Messrs G, K & M M Nassif & Messrs A G Eaton, R Kay"/>
<Jockey id="81293" name="Grant Van Niekerk"/>
<JockeyColours filename="20121101vaa104502.png" description="Red, red and grey checked sleeves, grey cap, red star"/>
<Colour type="ch"/>
<Sex type="f"/>
<Breeding type="Sire" name="Go Deputy" bred="USA" yearBorn="2000"/><Breeding type="Dam" name="Frostbite" bred="SAF" yearBorn="2002"/><Breeding type="DamSire" name="Western Winter" bred="USA" yearBorn="1900"/>
<FoalDate date="20081003"/>
<ForecastPrice>
<Price numerator="14" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1756220" name="Margot On Stage" bred="SAF">
<Cloth number="3"/>
<Drawn stall="8"/>
<FormFigures figures="345342" type="FlatSix"/>
<LastRunDays type="Flat" days="16"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="41149" name="Roy Magner"/>
<Owner name="Messers M Zackey, S Sheik & D G Zackey"/>
<Jockey id="28799" name="K Zechner"/>
<JockeyColours filename="20121101vaa104503.png" description="Black and turquoise halved vertically, turquoise sleeves, halved cap"/>
<Colour type="b"/>
<Sex type="f"/>
<Breeding type="Sire" name="Stagelight" bred="IRE" yearBorn="2002"/><Breeding type="Dam" name="Sweet Margot" bred="SAF" yearBorn="2003"/><Breeding type="DamSire" name="Saumarez" bred="UK" yearBorn="1987"/>
<FoalDate date="20090920"/>
<ForecastPrice>
<Price numerator="7" denominator="4"/>
</ForecastPrice>
</Horse>
<Horse id="1736110" name="Where Eagles Dare" bred="SAF">
<Cloth number="4"/>
<Drawn stall="14"/>
<FormFigures figures="5602" type="FlatSix"/>
<LastRunDays type="Flat" days="37"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="101933" name="Paul Peter" nationality="SAF"/>
<Owner name="Messrs G T Peter & Joel Peter"/>
<Jockey id="28071" name="Chad Little"/>
<JockeyColours filename="20121101vaa104504.png" description="Red and white checks, striped sleeves, white cap"/>
<Colour type="ch"/>
<Sex type="f"/>
<Breeding type="Sire" name="Silvano" bred="GER" yearBorn="1996"/><Breeding type="Dam" name="Aerial Dancer" bred="SAF" yearBorn="1991"/><Breeding type="DamSire" name="Dancing Champ" bred="USA"/>
<FoalDate date="20091025"/>
<ForecastPrice>
<Price numerator="5" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1796892" name="Always Camille" bred="SAF">
<Cloth number="5"/>
<Drawn stall="16"/>
<FormFigures figures="9" type="FlatSix"/>
<LastRunDays type="Flat" days="37"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="46483" name="Barend Daniel Botes"/>
<Owner name="Mr S J D Mynhardt"/>
<Jockey id="28083" name="Francois Herholdt"/>
<JockeyColours filename="20121101vaa104505.png" description="White, pink diamond hoop, white sleeves, pink collar and cuffs, diamonds on cap, white peak"/>
<Colour type="b"/>
<Sex type="f"/>
<Breeding type="Sire" name="Caesour" bred="USA" yearBorn="1990"/><Breeding type="Dam" name="Truely Yours" bred="SAF"/><Breeding type="DamSire" name="Northern Guest" bred="USA" yearBorn="1977"/>
<FoalDate date="20091022"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819719" name="Apple At Us" bred="SAF">
<Cloth number="6"/>
<Drawn stall="6"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="104350" name="Scott Kenny" nationality="SAF"/>
<Owner name="Messrs N S W Cullingworth, G D E Kahan, W McLean &"/>
<Jockey id="41571" name="Timothy Pretorius"/>
<JockeyColours filename="20121101vaa104506.png" description="Black, gold chevron, black sleeves, gold seams, black cap, gold diamond"/>
<Colour type="b"/>
<Sex type="f"/>
<Breeding type="Sire" name="Eyeofthetiger" bred="BRZ" yearBorn="2002"/><Breeding type="Dam" name="Apple At 'em" bred="SAF" yearBorn="2001"/><Breeding type="DamSire" name="Up And At 'em" bred="UK" yearBorn="1990"/>
<FoalDate date="20090919"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819720" name="Brave Princess" bred="SAF">
<Cloth number="7"/>
<Drawn stall="1"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="100130" name="Stanley M Ferreira"/>
<Owner name="Messrs S Rudd & M J Nunes"/>
<Jockey id="28344" name="Menno Malherbe"/>
<JockeyColours filename="20121101vaa104507.png" description="Red, pale blue v bib, red sleeves, pale blue cap"/>
<Colour type="b"/>
<Sex type="f"/>
<Breeding type="Sire" name="Mogok" bred="USA"/><Breeding type="Dam" name="Bravo Bamby" bred="SAF" yearBorn="1993"/><Breeding type="DamSire" name="Dolpour" bred="FR"/>
<FoalDate date="20090818"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819721" name="Dying Thunder" bred="SAF">
<Cloth number="8"/>
<Drawn stall="2"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="43065" name="Wallace Tolmay"/>
<Owner name="Mrs H E Truter"/>
<Jockey id="28088" name="Fanie Chambers"/>
<JockeyColours filename="20121101vaa104508.png" description="Red, white crossed sashes, black sleeves, black and white checked cap"/>
<Colour type="ch"/>
<Sex type="f"/>
<Breeding type="Sire" name="Fort Boyard" bred="SAF" yearBorn="1999"/><Breeding type="Dam" name="Wild Cat Strike" bred="SAF" yearBorn="2002"/><Breeding type="DamSire" name="Restructure" bred="IRE" yearBorn="1992"/>
<FoalDate date="20091101"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1736913" name="Fine Victory" bred="SAF">
<Cloth number="9"/>
<Drawn stall="11"/>
<FormFigures figures="6" type="FlatSix"/>
<LastRunDays type="Flat" days="205"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="61673" name="Grant Maroun"/>
<Owner name="Mr & Mrs Mark Aboud & Mesdames L J Schouten, Y J V"/>
<Jockey id="28377" name="M Yeni"/>
<JockeyColours filename="20121101vaa104509.png" description="Shocking pink, black diamonds, black collar and cuffs, shocking pink cap, black diamonds and peak"/>
<Colour type="ch"/>
<Sex type="f"/>
<Breeding type="Sire" name="Victory Moon" bred="SAF" yearBorn="1999"/><Breeding type="Dam" name="Fine Image" bred="SAF" yearBorn="2000"/><Breeding type="DamSire" name="Jallad" bred="USA" yearBorn="1988"/>
<FoalDate date="20090828"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1805775" name="Fortitude" bred="SAF">
<Cloth number="10"/>
<Drawn stall="9"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="55813" name="Michael Nicholas Houdalakis" nationality="SAF"/>
<Owner name="Stone Hill Stud (nom: Mr H C W Rix)"/>
<Jockey id="28018" name="C Maujean"/>
<JockeyColours filename="20121101vaa104510.png" description="Lime green, black diamond, lime green sleeves and cap, black diamond"/>
<Colour type="b"/>
<Sex type="f"/>
<Breeding type="Sire" name="Stronghold" bred="UK" yearBorn="2002"/><Breeding type="Dam" name="Mininski" bred="SNL"/><Breeding type="DamSire" name="Ahonoora" bred="UK"/>
<FoalDate date="20091010"/>
<ForecastPrice>
<Price numerator="3" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1819722" name="Idle Hour" bred="SAF">
<Cloth number="11"/>
<Drawn stall="4"/>
<FormFigures figures="" type="FlatSix"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="55813" name="Michael Nicholas Houdalakis" nationality="SAF"/>
<Owner name="Stone Hill Stud (nom: Mr H C W Rix)"/>
<Jockey id="28069" name="Francois Naude"/>
<JockeyColours filename="20121101vaa104511.png" description="Lime green, black diamond, lime green sleeves and cap, black diamond"/>
<Colour type="gr"/>
<Sex type="f"/>
<Breeding type="Sire" name="Imperial Stride" bred="UK" yearBorn="2001"/><Breeding type="Dam" name="Time Of My Life" bred="SAF" yearBorn="1994"/><Breeding type="DamSire" name="Royal Messenger" bred="SAF"/>
<FoalDate date="20091023"/>
<ForecastPrice>
<Price numerator="14" denominator="1"/>
</ForecastPrice>
</Horse>
<Horse id="1736926" name="Lady Jallad" bred="SAF">
<Cloth number="12"/>
<Drawn stall="5"/>
<FormFigures figures="075" type="FlatSix"/>
<LastRunDays type="Flat" days="5"/>
<Age years="3"/>
<Weight text="9 4" units="pounds" value="130"/>
<Trainer id="61673" name="Grant Maroun"/>
<Owner name="Mr G J Maroun"/>
<Jockey id="28082" name="Marco V'Rensburg"/>
<JockeyColours filename="20121101vaa104512.png" description="White, purple maltese cross and cap"/>
<Colour type="ch"/>
<Sex type="f"/>
<Breeding type="Sire" name="Announce" bred="SAF" yearBorn="1997"/><Breeding type="Dam" name="Hey Miss Jallad" bred="SAF" yearBorn="1994"/><Breeding type="DamSire" name="Jallad" bred="USA" yearBorn="1988"/>
<FoalDate date="20091014"/>
<ForecastPrice>
<Price numerator="20" denominator="1"/>
</ForecastPrice>
</Horse>
</Race>
</Meeting>
</HorseRacingCard>
Sorry for the long XML file, but it's what I'm working with :) - it actually contains more races and horses in each race than that, but I've shortened it down to just a few races - I was over the limit of posting restrictions. What is basically is, is a horse meeting, which contains it's races and the horses which ran in each race.
抱歉,很长的 XML 文件,但这就是我正在使用的 :) - 它实际上在每场比赛中包含更多的比赛和马匹,但我已将其缩短为几场比赛 - 我超过了限制发帖限制。基本上是,是一个马会,其中包含它的比赛和在每场比赛中奔跑的马匹。
I'm used to working with and seperating .csv files and have secured that, but the way things are going it's looking like I'm going to have to begin reading XML files and updating the database accordingly. Anyway, I'm a beginner to XML and vb .NET as a whole (a few month experience) and should probably not be jumping into such a complicated XML file so early on - I'll post my code below, and if somebody could point me in the right direction as to where I'm going wrong (probably a lot) and possibly provide me with some code/tutorials that will help me tackle this XML file then it would be much appreciated.
我习惯于使用和分离 .csv 文件并确保了它的安全,但事情的进展看起来好像我将不得不开始读取 XML 文件并相应地更新数据库。无论如何,我是 XML 和 vb .NET 整体的初学者(几个月的经验),可能不应该这么早就跳入如此复杂的 XML 文件 - 我将在下面发布我的代码,如果有人可以指出我哪里出错(可能很多)的正确方向,并可能为我提供一些代码/教程来帮助我处理这个 XML 文件,那么我将不胜感激。
What I'm looking to do is populate three different structures; Meeting, Race and Horse, with the corresponding information from the XML file. I can solve the database updating afterwards by myself, I believe (hopefully) :D
我要做的是填充三种不同的结构;会议、赛马和来自 XML 文件的相应信息。我可以自己解决之后的数据库更新,我相信(希望如此):D
Public Sub ExtractionService(ByVal spfile As FileInfo)
Dim strreader As New StreamReader(_sendpathname & spfile.Name, System.Text.Encoding.UTF8)
Dim xmlreader As XmlTextReader = New XmlTextReader(strreader)
xmlreader.WhitespaceHandling = WhitespaceHandling.None
Dim xmldoc As New XmlDocument()
xmldoc.Load(xmlreader)
Dim xml_nodelist As XmlNodeList = xmldoc.GetElementsByTagName("/HorseRacingCard/Meeting/Race/Horse")
Dim mStatus As String
Dim mID As Integer
Dim mCountry As String
Dim mCourse As String
Dim mDate As Integer
Dim mDrawAdvantage As String
Dim mAdvancedGoing As String
For Each mxmlnode As XmlNode In xmldoc.GetElementsByTagName("Meeting")
mStatus = mxmlnode.Attributes.ItemOf("status").InnerText
mID = mxmlnode.Attributes.ItemOf("id").InnerText
mCountry = mxmlnode.Attributes.ItemOf("country").InnerText
mCourse = mxmlnode.Attributes.ItemOf("course").InnerText
mDate = mxmlnode.Attributes.ItemOf("date").InnerText
mDrawAdvantage = mxmlnode.SelectSingleNode("DrawAdvantage").InnerText
mAdvancedGoing = mxmlnode.SelectSingleNode("AdvancedGoing").InnerText
_meeting.meetingStatus = mStatus
_meeting.meetingID = mID
_meeting.country = mCountry
_meeting.course = mCourse
_meeting.meetingDate = mDate
_meeting.drawAdvantage = mDrawAdvantage
_meeting.advancedGoing = mAdvancedGoing
Next
End Sub
This code manages to populate my meeting structure succesfully, but I just can't figure out I would go about populating the Race and Horse structures :( - I've followed a few tutorials and cannot seem to get my head around it. I understand I'm probably taking the wrong route here, and that there is potentially so much more I need to add/change to this in order for it to function the way I wish. Once these additions and changes have been highlighted, I believe I can then research these areas, and use the code which you guys can hopefully provide me with, to try tackle this.
这段代码成功地填充了我的会议结构,但我无法弄清楚我会去填充 Race and Horse 结构:( - 我已经学习了一些教程,但似乎无法理解它。我明白我可能在这里走错了路线,而且我可能需要为此添加/更改更多内容才能使其按我希望的方式运行。一旦突出显示这些添加和更改,我相信我可以然后研究这些领域,并使用你们希望提供给我的代码来尝试解决这个问题。
Again, all help is appreciated.
再次感谢所有帮助。
Thanks
谢谢
采纳答案by Gideon Engelberth
In situations like these, you are generally best off having each class have its own parsing function. Classes higher in the hierarchy can parse their own information and pass the elements for the contained classes to the respective methods.
在这种情况下,通常最好让每个类都有自己的解析函数。层次结构中较高的类可以解析它们自己的信息并将包含的类的元素传递给相应的方法。
Also I much prefer the API of and the extra syntax VB gives for the XLINQ classes (XElementand friends) over the XmlDocumentclasses, so I'll use them in my example. The general principal does not change.
此外,我更喜欢 VB 为 XLINQ 类(XElement和朋友)提供的 API 和额外的语法,而不是这些XmlDocument类,因此我将在我的示例中使用它们。总校长不变。
Class Meeting
'properties, etc
Public Shared Function Parse(element As XElement) As Meeting
'argument error checking here
Dim ret As New Meeting()
ret.Status = element.@status
ret.DrawAdvantage = element.<DrawAdvantage>.Value
'other properties
Dim parsedRaces = From re In element.<Race>
Select Race.Parse(re)
For Each r In parsedRaces
'add to meeting race collection
Next
Return ret
End Function
End Class
Class Race
'properties, etc
Public Shared Function Parse(element As XElement) As Race
'parse and return race data
End Function
End Class
Typically, I will not put methods that directly open a file on the classes themselves. Instead, whatever class determines the file name (form, window, view model, application) will be responsible for reading and writing the XElementto the file. Sometimes I will even move the Parse(and associated Save) methods to a different class if there are multiple ways an object is being stored or there are other layering concerns. In either case, I make the parse method create and return new instances of the class so I do not have to worry about partially mutated state if an exception is thrown.
通常,我不会将直接打开文件的方法放在类本身上。相反,任何确定文件名的类(表单、窗口、视图模型、应用程序)都将负责读取和写入XElement文件。有时,如果对象的存储方式有多种,或者存在其他分层问题,我什Parse至会将(和关联的Save)方法移动到不同的类。在任何一种情况下,我都会让 parse 方法创建并返回类的新实例,因此如果抛出异常,我不必担心部分变异的状态。

