我想在SQL Server中使用XML插入數據。我正在使用的XML是從SQL Server中的XML批量插入
<ArrayOfInfringementEntity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<InfringementEntity>
<infringementNumber>12345678911</infringementNumber>
<issueAgency>017</issueAgency>
<infringementType>1A</infringementType>
<infringementStatus>0</infringementStatus>
<batchRecordId>0</batchRecordId>
<incidentDate xsi:nil="true" />
<infringementSource>OTS</infringementSource>
<TypeOfNotice>0</TypeOfNotice>
<offenceEntity>
<offenceCode>7777</offenceCode>
<offenceDate>1999-05-31T00:00:00</offenceDate>
<offenceTime>121212</offenceTime>
<offenceLocation>ST56789</offenceLocation>
<offenceOwnerType>0</offenceOwnerType>
<offenceSuburb>SOUTH YARRA</offenceSuburb>
<site>ST56789</site>
<detectedSpeed>70</detectedSpeed>
<allegedSpeed>60</allegedSpeed>
<permittedSpeed>50</permittedSpeed>
<timeInRedLight>40</timeInRedLight>
<tollAmount>140</tollAmount>
<enforcementAllowance>310</enforcementAllowance>
<lookUpFee>510</lookUpFee>
<invoiceFee>130</invoiceFee>
</offenceEntity>
<vehicleEntity>
<vehicleClass>2</vehicleClass>
<vehicleMake>BMW</vehicleMake>
<vehicleModel>FOUR WHEELER</vehicleModel>
<bodyType>HEAVY</bodyType>
<primaryColour>GRN</primaryColour>
<manufactureYear>2010</manufactureYear>
<gvm>111</gvm>
<gcm>210</gcm>
<registrationNumber>CBD-1111</registrationNumber>
<registrationState>VIC</registrationState>
</vehicleEntity>
<obligationNumber>obligation1</obligationNumber>
<isDebtorDeceased>false</isDebtorDeceased>
</InfringementEntity>
</ArrayOfInfringementEntity>
我想在臨時表中撕碎這個XML。我試過使用
create table #InfTemp
(infringementNumber Varchar(10),issueAgency varchar(5),infringementType varchar(5), offenceCode int,vehicleClass int,obligationNumber varchar(11)
)
Insert into #InfTemp
SELECT PLIxml.infringementNumber, PLIxml.issueAgency,PLIxml.infringementType,
PLIxml.offenceCode , PLIxml.vehicleClass ,PLIxml.obligationNumber
FROM OPENXML (@output, 'ArrayOfInfringementEntity/InfringementEntity',2)
WITH
( infringementNumber Varchar(10),issueAgency varchar(5),infringementType varchar(5),offenceCode int,vehicleClass int,obligationNumber varchar(11)
) PLIxml
但是,我在Offencecode和車輛類中得到空值。據我所知,這是有道理的,因爲<offenceCode>
是<offenceEntity>
的子節點。而且我不是專門閱讀<offenceEntity>
節點。請幫忙。
我不知道我會在XML中獲得多少行數據。據我所知,你已經使用[1]符號來引用節點。我將如何參考所有行。 – 2011-01-11 18:29:04