2015-04-05 33 views
0

XML數據Scala的情況下階層結構看起來像對於複雜的XML

<bd> 
    <oied> 
     <oeuo>XYZWC999</oeuo> 
     <oedo>SorNbteluk=ONRM_ROOT_MO_R,SrobeNhbwk=XYZWC999,MoetxeoCt=XYZWC999</oedo> 
     <oesw>CXP9021776/2_R2CA15</oesw> 
    </oied> 
    <bi> 
     <bts>20150205141500Z</bts> 
     <gp>900</gp> 
     <bt>paaoCukStSteboshRrttcps</bt> 
     <bt>pptubthCaStctoSekSos</bt> 
     <bv> 
     <biod>MaebdlgeaooeEt=1,TparswotterNorok=1,Ntcp=Kub-9</biod> 
     <r>4578</r> 
     <r>10769</r> 
     </bv> 
     <bv> 
     <biod>MEegoedbaaloet=1,TreatoorNtosrpwk=1,Ntcp=1</biod> 
     <r>11021</r> 
     <r>86235</r> 
     </bv> 
     <bv> 
     <biod>MdaolaeeobeEgt=1,TretrowooNrtsapk=1,Nctp=Kub-7</biod> 
     <r>0</r> 
     <r>0</r> 
     </bv> 
    </bi> 
</bd> 

我是新來斯卡拉,我能想出的基本結構。

case class xmldata(oeuo : String, oedo : String, oesw: String, bts: String, gp : Int, btArray : List[String]) 

什麼是這個XML數據優化的Scala案例類(與集合)?

回答

1

這只是case類的樹:

case class Bd(oied: Oied, bi: Bi) 
case class Oied(oeuo: String, oedo: String, oesw: String) 
case class Bi(bts: String, gp: String, bt: List[String], bv: List[Bv]) 
case class Bv(biod: String, r: List[String]) 

如果順序並不重要 - 你可能會(在您的解決方案等)使用Set代替List

您也可以將其壓平一點,但可能很難用xml綁定工具進行映射,然後

case class Bd(oeuo: String, oedo: String, oesw: String, bts: String, gp: String, bt: List[String], bv: List[Bv]) 

最扁平和最不可操作的版本(不推薦):

case class Bd(oeuo: String, oedo: String, oesw: String, bts: String, gp: String, bt: List[String], biods: List[String], rs: List[List[String]])