0
我有一個XML文件:解析xml。與關係(一到多)對象
<?xml version='1.0' encoding='windows-1251' standalone='yes'?><XML>
<Result>Ok</Result>
<Error></Error>
<Remark></Remark>
<Data>
<Theatres>
<Theatre ID='1' ShowBusyPlaces='1'> // maybe more than one
<Name><![CDATA[PlaceName]]></Name>
<NameFull><![CDATA[PlaceName]]></NameFull>
<Remark><![CDATA[]]></Remark>
<Address><![CDATA[]]></Address>
<Halls Count='3'>
<Hall ID='1'>
<Name><![CDATA[Redisson]]></Name>
<Levels Count='1'>
<Level ID='1' Geometry='1'> // maybe more than one
<Name><![CDATA[Radisson]]></Name>
</Level>
</Levels>
</Hall>
<Hall ID='3'>
<Name><![CDATA[Test 2]]></Name>
<Levels Count='0'></Levels>
</Hall>
<Hall ID='2'>
<Name><![CDATA[тест]]></Name>
<Levels Count='1'>
<Level ID='4' Geometry='2'>
<Name><![CDATA[ттт]]></Name>
</Level>
</Levels>
</Hall>
</Halls>
</Theatre>
</Theatres>
</Data>
</XML>
而且,我有兩個類:BasePlace
和HallPlan
(關係作爲一個一對多)
BasePlace
: OID, Name, Address
HallPlan
:OID, BasePlaceId, HallId, LevelId
例如上述結果必須是:
BasePlace table:
OID Name Address
1 PlaceName
HallPlan table:
OID BasePlaceId, HallId, LevelId
1 1 1 1
2 1 2 4
3 1 3 null
該查詢返回只填充BasePlace
對象:
var places = from element in XDocument.Parse(xml).Descendants("Theatre")
select new BasePlace
{
OIDPremiera = (int) element.Attribute("ID"),
Name = (string) element.Element("Name"),
Address = (string) element.Element("Address"),
};
如何填寫HallPlan
正確(與各界和有關BasePlace
)? 謝謝。