我正在尝试将一组公开可用的数据导入 SQL Server 数据库。我是一个新手,并且正在为此苦苦挣扎-今天大部分时间都花在了这个问题上……无论我做了多少调整,它都不会返回任何结果。在线提供的示例,我可以遵循(并工作),但是当我尝试使用我拥有的实际数据时,我没有得到任何结果。对此的任何帮助都非常感谢。
我正在按照以下 URL 中的步骤操作:
我使用的 SQL 如下(我的 XML 文件名为 D:\OpenXMLTesting.xml):
CREATE DATABASE OPENXMLTesting
GO
USE OPENXMLTesting
GO
CREATE TABLE XMLwithOpenXML
(
Id INT IDENTITY PRIMARY KEY,
XMLData XML,
LoadedDateTime DATETIME
)
INSERT INTO XMLwithOpenXML(XMLData, LoadedDateTime)
SELECT CONVERT(XML, BulkColumn) AS BulkColumn, GETDATE()
FROM OPENROWSET(BULK 'D:\OpenXMLTesting.xml', SINGLE_BLOB) AS x;
SELECT * FROM XMLwithOpenXML
DECLARE @XML AS XML, @hDoc AS INT, @SQL NVARCHAR (MAX)
SELECT @XML = XMLData FROM XMLwithOpenXML
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML
SELECT Id
FROM OPENXML(@hDoc, 'BizData/Pyld/Document/FinInstrmRptgRefDataRpt/RefData/FinInstrmGnlAttrbts')
WITH
(
Id [varchar](50) '@Id'
)
EXEC sp_xml_removedocument @hDoc
GO
原始 XML 包含以下数据:-
<?xml version="1.0" encoding="UTF-8"?>
-<BizData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:head.003.001.01" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:head.003.001.01 head.003.001.01.xsd">
+<Hdr>
-<Pyld>
-<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:auth.017.001.02" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:auth.017.001.02 auth.017.001.02_ESMAUG_FULINS_1.1.0.xsd">
-<FinInstrmRptgRefDataRpt>
+<RptHdr>
-<RefData>
-<FinInstrmGnlAttrbts>
<Id>DE000C3JALS0</Id>
<FullNm>EAA3 SI 20211220 CS</FullNm>
<ShrtNm>EEX/EUAA P AUCTION SPOT</ShrtNm>
<ClssfctnTp>ITNXXX</ClssfctnTp>
<NtnlCcy>EUR</NtnlCcy>
<CmmdtyDerivInd>false</CmmdtyDerivInd>
</FinInstrmGnlAttrbts>
<Issr>529900J0JGLSFDWNFC20</Issr>
-<TradgVnRltdAttrbts>
<Id>XEER</Id>
<IssrReq>false</IssrReq>
<FrstTradDt>2015-03-25T06:00:00Z</FrstTradDt>
<TermntnDt>2021-12-20T23:59:59Z</TermntnDt>
</TradgVnRltdAttrbts>
-<DerivInstrmAttrbts>
<PricMltplr>500</PricMltplr>
-<AsstClssSpcfcAttrbts>
-<Cmmdty>
-<Pdct>
-<Envttl>
-<Emssns>
<BasePdct>ENVR</BasePdct>
<SubPdct>EMIS</SubPdct>
<AddtlSubPdct>EUAA</AddtlSubPdct>
</Emssns>
</Envttl>
</Pdct>
<TxTp>OTHR</TxTp>
<FnlPricTp>EXOF</FnlPricTp>
</Cmmdty>
</AsstClssSpcfcAttrbts>
</DerivInstrmAttrbts>
-<TechAttrbts>
<RlvntCmptntAuthrty>DE</RlvntCmptntAuthrty>
-<PblctnPrd>
<FrDt>2019-07-16</FrDt>
</PblctnPrd>
<RlvntTradgVn>XEER</RlvntTradgVn>
</TechAttrbts>
</RefData>
-<RefData>
-<FinInstrmGnlAttrbts>
<Id>DE000C3JALT8</Id>
<FullNm>T3PA SI 20211220 CS</FullNm>
<ShrtNm>EEX/EUA P AUCTION SPOT</ShrtNm>
<ClssfctnTp>ITNXXX</ClssfctnTp>
<NtnlCcy>EUR</NtnlCcy>
<CmmdtyDerivInd>false</CmmdtyDerivInd>
</FinInstrmGnlAttrbts>
<Issr>529900J0JGLSFDWNFC20</Issr>
-<TradgVnRltdAttrbts>
<Id>XEER</Id>
<IssrReq>false</IssrReq>
<FrstTradDt>2015-03-25T06:00:00Z</FrstTradDt>
<TermntnDt>2021-12-20T23:59:59Z</TermntnDt>
</TradgVnRltdAttrbts>
-<DerivInstrmAttrbts>
<PricMltplr>500</PricMltplr>
-<AsstClssSpcfcAttrbts>
-<Cmmdty>
-<Pdct>
-<Envttl>
-<Emssns>
<BasePdct>ENVR</BasePdct>
<SubPdct>EMIS</SubPdct>
<AddtlSubPdct>EUAE</AddtlSubPdct>
</Emssns>
</Envttl>
</Pdct>
<TxTp>OTHR</TxTp>
<FnlPricTp>EXOF</FnlPricTp>
</Cmmdty>
</AsstClssSpcfcAttrbts>
</DerivInstrmAttrbts>
-<TechAttrbts>
<RlvntCmptntAuthrty>DE</RlvntCmptntAuthrty>
-<PblctnPrd>
<FrDt>2019-07-16</FrDt>
</PblctnPrd>
<RlvntTradgVn>XEER</RlvntTradgVn>
</TechAttrbts>
</RefData>
-<RefData>
-<FinInstrmGnlAttrbts>
<Id>DE000F5PP026</Id>
<FullNm>SEME SI 20211220 CS</FullNm>
<ShrtNm>EEX/F 20211220</ShrtNm>
<ClssfctnTp>ITNXXX</ClssfctnTp>
<NtnlCcy>EUR</NtnlCcy>
<CmmdtyDerivInd>true</CmmdtyDerivInd>
</FinInstrmGnlAttrbts>
<Issr>529900J0JGLSFDWNFC20</Issr>
-<TradgVnRltdAttrbts>
<Id>XEER</Id>
<IssrReq>false</IssrReq>
<FrstTradDt>2015-03-25T06:00:00Z</FrstTradDt>
<TermntnDt>2021-12-20T23:59:59Z</TermntnDt>
</TradgVnRltdAttrbts>
-<DerivInstrmAttrbts>
<PricMltplr>1000</PricMltplr>
-<AsstClssSpcfcAttrbts>
-<Cmmdty>
-<Pdct>
-<Envttl>
-<Emssns>
<BasePdct>ENVR</BasePdct>
<SubPdct>EMIS</SubPdct>
<AddtlSubPdct>EUAE</AddtlSubPdct>
</Emssns>
</Envttl>
</Pdct>
<TxTp>OTHR</TxTp>
<FnlPricTp>EXOF</FnlPricTp>
</Cmmdty>
</AsstClssSpcfcAttrbts>
</DerivInstrmAttrbts>
-<TechAttrbts>
<RlvntCmptntAuthrty>DE</RlvntCmptntAuthrty>
-<PblctnPrd>
<FrDt>2018-12-04</FrDt>
</PblctnPrd>
<RlvntTradgVn>XEER</RlvntTradgVn>
</TechAttrbts>
</RefData>
-<RefData>
-<FinInstrmGnlAttrbts>
<Id>DE000F5PPQ38</Id>
<FullNm>SEMA SI 20211220 CS</FullNm>
<ShrtNm>EEX/F 20211220</ShrtNm>
<ClssfctnTp>ITNXXX</ClssfctnTp>
<NtnlCcy>EUR</NtnlCcy>
<CmmdtyDerivInd>true</CmmdtyDerivInd>
</FinInstrmGnlAttrbts>
<Issr>529900J0JGLSFDWNFC20</Issr>
-<TradgVnRltdAttrbts>
<Id>XEER</Id>
<IssrReq>false</IssrReq>
<FrstTradDt>2015-03-25T06:00:00Z</FrstTradDt>
<TermntnDt>2021-12-20T23:59:59Z</TermntnDt>
</TradgVnRltdAttrbts>
-<DerivInstrmAttrbts>
<PricMltplr>1000</PricMltplr>
-<AsstClssSpcfcAttrbts>
-<Cmmdty>
-<Pdct>
-<Envttl>
-<Emssns>
<BasePdct>ENVR</BasePdct>
<SubPdct>EMIS</SubPdct>
<AddtlSubPdct>EUAA</AddtlSubPdct>
</Emssns>
</Envttl>
</Pdct>
<TxTp>OTHR</TxTp>
<FnlPricTp>EXOF</FnlPricTp>
</Cmmdty>
</AsstClssSpcfcAttrbts>
</DerivInstrmAttrbts>
-<TechAttrbts>
<RlvntCmptntAuthrty>DE</RlvntCmptntAuthrty>
-<PblctnPrd>
<FrDt>2018-12-04</FrDt>
</PblctnPrd>
<RlvntTradgVn>XEER</RlvntTradgVn>
</TechAttrbts>
</RefData>
-<RefData>
-<FinInstrmGnlAttrbts>
<Id>DE000F5PPYW2</Id>
<FullNm>SEMC SI 20211220 CS</FullNm>
<ShrtNm>EEX/F 20211220</ShrtNm>
<ClssfctnTp>ITNXXX</ClssfctnTp>
<NtnlCcy>EUR</NtnlCcy>
<CmmdtyDerivInd>true</CmmdtyDerivInd>
</FinInstrmGnlAttrbts>
<Issr>529900J0JGLSFDWNFC20</Issr>
-<TradgVnRltdAttrbts>
<Id>XEER</Id>
<IssrReq>false</IssrReq>
<FrstTradDt>2015-03-25T06:00:00Z</FrstTradDt>
<TermntnDt>2021-12-20T23:59:59Z</TermntnDt>
</TradgVnRltdAttrbts>
-<DerivInstrmAttrbts>
<PricMltplr>1000</PricMltplr>
-<AsstClssSpcfcAttrbts>
-<Cmmdty>
-<Pdct>
-<Envttl>
-<Emssns>
<BasePdct>ENVR</BasePdct>
<SubPdct>EMIS</SubPdct>
<AddtlSubPdct>CERE</AddtlSubPdct>
</Emssns>
</Envttl>
</Pdct>
<TxTp>OTHR</TxTp>
<FnlPricTp>EXOF</FnlPricTp>
</Cmmdty>
</AsstClssSpcfcAttrbts>
</DerivInstrmAttrbts>
-<TechAttrbts>
<RlvntCmptntAuthrty>DE</RlvntCmptntAuthrty>
-<PblctnPrd>
<FrDt>2018-12-04</FrDt>
</PblctnPrd>
<RlvntTradgVn>XEER</RlvntTradgVn>
</TechAttrbts>
</RefData>
</FinInstrmRptgRefDataRpt>
</Document>
</Pyld>
</BizData>
非常感谢任何帮助。
谢谢