Hi Eric,
My xml file has multiple namespaces like below.
<NewHire xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wta="http://www.kronos.com/wta">
The xml file namespace is:
<?xml version="1.0" encoding="utf-8"?>
<NewHires batchId="8569021" batchDate="4/1/2015 6:34:16 PM" recordCount="4">
<NewHire xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wta="http://www.kronos.com/wta">
<TypeOfHire>
<StandardValue>NewHire</StandardValue>
</TypeOfHire>
<EmployeeInfo>
<PersonName>
<GivenName>Hot</GivenName>
<MiddleName />
<FamilyName>Buns</FamilyName>
</PersonName>
.....
I modified my query based on your recommendation, I received below error.
DECLARE @x XML
SELECT @x=N
FROM OPENROWSET (BULK 'D:\Temp\Bad.Test.xml', SINGLE_BLOB) as NewHire (N)
DECLARE @hdoc int
EXEC sp_xml_preparedocument @hdoc OUTPUT, @x, '<a:NewHire xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wta="'">http://www.kronos.com/wta">'
SELECT *
FROM OPENXML (@hdoc, '/NewHires/a:NewHire/a:EmployeeInfo/a:PersonName', 2)
WITH
(
BatchDate datetime '../../../@batchDate',
BatchId int '../../../@batchId',
GivenName varchar(30) 'a:GivenName',
FamilyName varchar(30) 'a:FamilyName'
)
EXEC sp_xml_removedocument @hdoc
Here is the error:
(1 row(s) affected)
The XML parse error 0xc00ce01d occurred on line number 1, near the XML text "<a:NewHire xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wta="http://www.kronos.com/wta">".
Msg 6602, Level 16, State 2, Procedure sp_xml_preparedocument, Line 1
The error description is 'Reference to undeclared namespace prefix: 'a'.'.
Msg 8179, Level 16, State 5, Line 12
Could not find prepared statement with handle 0.
Msg 6607, Level 16, State 3, Procedure sp_xml_removedocument, Line 1
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.
How do I define the tag for multiple namespsaces?
Thanks again!