Jordan_WM
asked on
Parsing XML into SQL
Hello,
I have the following XML file which has data in the attributes and within the tags I trying to figure out the best approach to get this data into SQL. I am able to pull out the attributes but what happens when I pull out the data with in the tags it is all concatenated together as one value.
What would be the best approach to this multiple passes?
LJ
<Package>
<InvestmentVehicle _Id="F00000Q9RW">
<Name LanguageId="0L00000122">Ne ed Data From Here</Name>
<LegalName LanguageId="0L00000122">Ne ed Data From Here</LegalName>
<FundServList>
<FundServId CurrencyId="CU$$$$$USD">PM O2406</Fun dServId>
</FundServList>
</InvestmentVehicle>
<InvestmentVehicle _Id="F00000LXW6">
<Name LanguageId="0L00000138">CA N Revenu (M) 100/100</Name>
<Name LanguageId="0L00000122">CA N Income (M) 100/100</Name>
<LegalName LanguageId="0L00000138">CA N Revenu (M) 100/100</LegalName>
<LegalName LanguageId="0L00000122">CA N Income (M) 100/100</LegalName>
<FundServList>
<FundServId CurrencyId="CU$$$$$CAD">CA N1073</Fun dServId>
<FundServId CurrencyId="CU$$$$$CAD">CA N873</Fund ServId>
<FundServId CurrencyId="CU$$$$$CAD">CA N973</Fund ServId>
</FundServList>
</InvestmentVehicle>
</Package>
I have the following XML file which has data in the attributes and within the tags I trying to figure out the best approach to get this data into SQL. I am able to pull out the attributes but what happens when I pull out the data with in the tags it is all concatenated together as one value.
What would be the best approach to this multiple passes?
LJ
<Package>
<InvestmentVehicle _Id="F00000Q9RW">
<Name LanguageId="0L00000122">Ne
<LegalName LanguageId="0L00000122">Ne
<FundServList>
<FundServId CurrencyId="CU$$$$$USD">PM
</FundServList>
</InvestmentVehicle>
<InvestmentVehicle _Id="F00000LXW6">
<Name LanguageId="0L00000138">CA
<Name LanguageId="0L00000122">CA
<LegalName LanguageId="0L00000138">CA
<LegalName LanguageId="0L00000122">CA
<FundServList>
<FundServId CurrencyId="CU$$$$$CAD">CA
<FundServId CurrencyId="CU$$$$$CAD">CA
<FundServId CurrencyId="CU$$$$$CAD">CA
</FundServList>
</InvestmentVehicle>
</Package>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
DECLARE @XML AS XML, @hDoc AS INT, @SQL NVARCHAR (MAX)
SELECT @XML = XmlCol FROM T
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML
SELECT _Id--, Name--, LegalName, CurrencyId
, FundServId
FROM OPENXML(@hDoc, 'Package/InvestmentVehicle
WITH
(
_Id [varchar](50) '../../@_Id',
Name [varchar](100) '../../Name',
LegalName [varchar](100) '../../LegalName',
CurrencyId [varchar](100) '@CurrencyId',
FundServId [varchar](100) '../FundServId'
)
EXEC sp_xml_removedocument @hDoc
GO