在直接的PHP中解析此XML的最简单方法是什么,还是我需要一个特殊对象?

时间:2019-05-26 18:15:47

标签: xml web xml-parsing string-parsing

我必须全天解析大量XML,才能从当天在同一条赛道的单个比赛的单个市场的这个很小的例子中获得节点和属性值。因此,可能有30多个赛道(全球),每个赛道在不同时间进行8场比赛,并且每个市场上有2-40名跑步者。另外,我只在这里输出WIN市场。可能会有PLACE市场,PLACE 5 Spots市场以及许多其他市场。

很抱歉遇到任何格式问题

<?xml version="1.0" encoding="utf-8"?><root ID="1"><SPORT NAME="Horse Racing" ID="100004"><EVENT NAME="UK Racing" ID="190538"><SUBEVENT NAME="Perth (26th April 2019)" ID="5990925" DATE="2019-04-25 23:01:00"><SUBEVENT1 NAME="13:30 Perth" ID="5990926" DATE="2019-04-26 12:30:00"><MARKET NAME="Win Market" ID="15346430" ODDS_SYSTEM="BL"><LINK URL="https://www.betdaq.com/exchange/Horse-Racing-13-30-Perth/5990926/15346430" MOBILE_URL="https://mobile03.betdaq.com/#market?mId=15346430" /><SELECTION NAME=" 3 Vision Du Puy" ID="97698108"><OUTCOME NAME="|BACK|  3 Vision Du Puy"><ODDS POLARITY="BACK"><PRICE VALUE="1.54"><AMOUNT CURRENCY="USD" VALUE="6" /><AMOUNT CURRENCY="GBP" VALUE="4" /><AMOUNT CURRENCY="EUR" VALUE="5" /></PRICE><PRICE VALUE="1.53"><AMOUNT CURRENCY="USD" VALUE="73" /><AMOUNT CURRENCY="GBP" VALUE="56" /><AMOUNT CURRENCY="EUR" VALUE="65" /></PRICE><PRICE VALUE="1.52"><AMOUNT CURRENCY="USD" VALUE="38" /><AMOUNT CURRENCY="GBP" VALUE="29" /><AMOUNT CURRENCY="EUR" VALUE="34" /></PRICE></ODDS></OUTCOME><OUTCOME NAME="|LAY|  3 Vision Du Puy"><ODDS POLARITY="LAY"><PRICE VALUE="1.58"><AMOUNT CURRENCY="USD" VALUE="3" /><AMOUNT CURRENCY="GBP" VALUE="3" /><AMOUNT CURRENCY="EUR" VALUE="3" /></PRICE><PRICE VALUE="1.60"><AMOUNT CURRENCY="USD" VALUE="14" /><AMOUNT CURRENCY="GBP" VALUE="11" /><AMOUNT CURRENCY="EUR" VALUE="13" /></PRICE><PRICE VALUE="1.61"><AMOUNT CURRENCY="USD" VALUE="4" /><AMOUNT CURRENCY="GBP" VALUE="3" /><AMOUNT CURRENCY="EUR" VALUE="4" /></PRICE></ODDS></OUTCOME></SELECTION><SELECTION NAME=" 1 Edene D'Arc" ID="97698109"><OUTCOME NAME="|BACK|  1 Edene D'Arc"><ODDS POLARITY="BACK"><PRICE VALUE="3.10"><AMOUNT CURRENCY="USD" VALUE="138" /><AMOUNT CURRENCY="GBP" VALUE="107" /><AMOUNT CURRENCY="EUR" VALUE="124" /></PRICE><PRICE VALUE="3.05"><AMOUNT CURRENCY="USD" VALUE="46" /><AMOUNT CURRENCY="GBP" VALUE="35" /><AMOUNT CURRENCY="EUR" VALUE="41" /></PRICE><PRICE VALUE="3.00"><AMOUNT CURRENCY="USD" VALUE="18" /><AMOUNT CURRENCY="GBP" VALUE="14" /><AMOUNT CURRENCY="EUR" VALUE="17" /></PRICE></ODDS></OUTCOME><OUTCOME NAME="|LAY|  1 Edene D'Arc"><ODDS POLARITY="LAY"><PRICE VALUE="3.30"><AMOUNT CURRENCY="USD" VALUE="16" /><AMOUNT CURRENCY="GBP" VALUE="13" /><AMOUNT CURRENCY="EUR" VALUE="15" /></PRICE><PRICE VALUE="3.35"><AMOUNT CURRENCY="USD" VALUE="18" /><AMOUNT CURRENCY="GBP" VALUE="13" /><AMOUNT CURRENCY="EUR" VALUE="16" /></PRICE><PRICE VALUE="3.45"><AMOUNT CURRENCY="USD" VALUE="16" /><AMOUNT CURRENCY="GBP" VALUE="13" /><AMOUNT CURRENCY="EUR" VALUE="15" /></PRICE></ODDS></OUTCOME></SELECTION><SELECTION NAME=" 2 Off The Hook" ID="97698110" WITHDRAWN="TRUE"><OUTCOME NAME="|BACK|  2 Off The Hook"><ODDS POLARITY="BACK" /></OUTCOME><OUTCOME NAME="|LAY|  2 Off The Hook"><ODDS POLARITY="LAY" /></OUTCOME></SELECTION><SELECTION NAME=" 6 West Coast Lass" ID="97698111"><OUTCOME NAME="|BACK|  6 West Coast Lass"><ODDS POLARITY="BACK"><PRICE VALUE="31.00"><AMOUNT CURRENCY="USD" VALUE="11" /><AMOUNT CURRENCY="GBP" VALUE="8" /><AMOUNT CURRENCY="EUR" VALUE="10" /></PRICE><PRICE VALUE="28.00"><AMOUNT CURRENCY="USD" VALUE="14" /><AMOUNT CURRENCY="GBP" VALUE="11" /><AMOUNT CURRENCY="EUR" VALUE="13" /></PRICE><PRICE VALUE="27.00"><AMOUNT CURRENCY="USD" VALUE="9" /><AMOUNT CURRENCY="GBP" VALUE="7" /><AMOUNT CURRENCY="EUR" VALUE="8" /></PRICE></ODDS></OUTCOME><OUTCOME NAME="|LAY|  6 West Coast Lass"><ODDS POLARITY="LAY"><PRICE VALUE="37.00"><AMOUNT CURRENCY="USD" VALUE="2" /><AMOUNT CURRENCY="GBP" VALUE="2" /><AMOUNT CURRENCY="EUR" VALUE="2" /></PRICE><PRICE VALUE="42.00"><AMOUNT CURRENCY="USD" VALUE="4" /><AMOUNT CURRENCY="GBP" VALUE="3" /><AMOUNT CURRENCY="EUR" VALUE="3" /></PRICE><PRICE VALUE="43.00"><AMOUNT CURRENCY="USD" VALUE="4" /><AMOUNT CURRENCY="GBP" VALUE="3" /><AMOUNT CURRENCY="EUR" VALUE="3" /></PRICE></ODDS></OUTCOME></SELECTION><SELECTION NAME=" 4 Fig's Pride" ID="97698112"><OUTCOME NAME="|BACK|  4 Fig's Pride"><ODDS POLARITY="BACK"><PRICE VALUE="116.00"><AMOUNT CURRENCY="USD" VALUE="6" /><AMOUNT CURRENCY="GBP" VALUE="4" /><AMOUNT CURRENCY="EUR" VALUE="5" /></PRICE><PRICE VALUE="110.00"><AMOUNT CURRENCY="USD" VALUE="1" /><AMOUNT CURRENCY="GBP" VALUE="1" /><AMOUNT CURRENCY="EUR" VALUE="1" /></PRICE><PRICE VALUE="108.00"><AMOUNT CURRENCY="USD" VALUE="9" /><AMOUNT CURRENCY="GBP" VALUE="7" /><AMOUNT CURRENCY="EUR" VALUE="8" /></PRICE></ODDS></OUTCOME><OUTCOME NAME="|LAY|  4 Fig's Pride"><ODDS POLARITY="LAY" /></OUTCOME></SELECTION><SELECTION NAME=" 5 Sueno Toms" ID="97698113"><OUTCOME NAME="|BACK|  5 Sueno Toms"><ODDS POLARITY="BACK"><PRICE VALUE="1000.00"><AMOUNT CURRENCY="USD" VALUE="350" /><AMOUNT CURRENCY="GBP" VALUE="271" /><AMOUNT CURRENCY="EUR" VALUE="314" /></PRICE><PRICE VALUE="995.00"><AMOUNT CURRENCY="USD" VALUE="2" /><AMOUNT CURRENCY="GBP" VALUE="1" /><AMOUNT CURRENCY="EUR" VALUE="2" /></PRICE><PRICE VALUE="975.00"><AMOUNT CURRENCY="USD" VALUE="6" /><AMOUNT CURRENCY="GBP" VALUE="4" /><AMOUNT CURRENCY="EUR" VALUE="5" /></PRICE></ODDS></OUTCOME><OUTCOME NAME="|LAY|  5 Sueno Toms"><ODDS POLARITY="LAY" /></OUTCOME></SELECTION></MARKET></SUBEVENT1></SUBEVENT></EVENT></SPORT></root>

我认为编辑器可能会识别XML。

我已经习惯了基本的xml解析,但是使用纯PHP或诸如SimplePie或其他第3方对象之类的插件会更好。

我只想让我容易获得比赛中的每种选择(马匹)(这只显示了一场比赛和WIN市场),以及在下的3种价格。和其余的信息将很有用,例如在下获得时间,路线名称,市场ID,马匹名称等 我习惯于获取节点值,但我想创建一个简单的对象,其中包含种族,路线,时间,跑步者列表,以及每个跑步者下的3个后退价格和3个平手价格,然后我可以将其保存到数据库。

非常感谢您提前提供帮助

0 个答案:

没有答案