XML import til tabel i ms sql
Jeg skal have data fra en XML fil indsat i en tabel i ms sql. XML filen har tidligere set anderledes ud, men er nu desværre lavet om og nu kan jeg simpelthen ikke trække data ud. Så håber virkelige på hjælp her :)Jeg har en XML fil i dette som ser således ud.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<export xmlns="http://eu.europa.ec/fpi/fsd/export" generationDate="2016-05-30T19:50:05.779+02:00" globalFileId="108740">
<sanctionEntity designationDetails="" unitedNationId="" logicalId="1">
<regulation regulationType="amendment" organisationType="commission" publicationDate="2016-02-17" entryIntoForceDate="2016-02-18" numberTitle="2016/218 (OJ L40)" programme="ZWE" logicalId="92906">
<publicationUrl>http://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:32016R0218&from=EN</publicationUrl>
</regulation>
<subjectType code="person" classificationCode="P"/>
<nameAlias firstName="Robert" middleName="Gabriel" lastName="Mugabe" wholeName="Robert Gabriel Mugabe" function="President" gender="M" title="" nameLanguage="" strong="true" regulationLanguage="en" logicalId="1">
<regulationSummary regulationType="amendment" publicationDate="2005-06-16" numberTitle="898/2005 (OJ L153)" publicationUrl="http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2005:153:0009:0014:EN:PDF"/>
</nameAlias>
<birthdate circa="false" calendarType="GREGORIAN" city="" zipCode="" birthdate="1924-02-21" dayOfMonth="21" monthOfYear="2" year="1924" region="" place="" countryIso2Code="00" countryDescription="UNKNOWN" regulationLanguage="en" logicalId="1">
<regulationSummary regulationType="amendment" publicationDate="2005-06-16" numberTitle="898/2005 (OJ L153)" publicationUrl="http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2005:153:0009:0014:EN:PDF"/>
</birthdate>
<identification diplomatic="false" knownExpired="false" knownFalse="false" reportedLost="false" revokedByIssuer="false" issuedBy="" latinNumber="" nameOnDocument="" number="AD001095" region="" countryIso2Code="00" countryDescription="UNKNOWN" identificationTypeCode="passport" identificationTypeDescription="National passport" regulationLanguage="en" logicalId="315">
<remark>(passport)</remark>
<regulationSummary regulationType="amendment" publicationDate="2012-02-22" numberTitle="151/2012 (OJ L49)" publicationUrl="http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2012:049:0002:0016:EN:PDF"/>
</identification>
</sanctionEntity>
</export>
Det script jeg kører i SSMS ser således ud:
DECLARE @x xml
SELECT @x = T
FROM OPENROWSET (BULK 'C:\temp\01-06-2016Copy.xml', SINGLE_BLOB) AS Terrorliste(T)
DECLARE @hdoc int
EXEC sp_xml_preparedocument @hdoc OUTPUT, @x
SELECT *
FROM OPENXML (@hdoc, '/export/sanctionEntity/nameAlias', 2)
WITH (
logicalId varchar(10),
wholeName varchar(400),
lastName varchar(200),
middlenName varchar(200),
firstName varchar(200))
EXEC sp_xml_removedocument @hdoc
Håber der er nogen der lige gider kaste et blik og evt. finde fejl. Stien i FROM OPENXML mener jeg er korrekt.
Takker :)