Saturday, February 25, 2012

OPENXML with Multiple Namespace

Hi
I would appriciate if any one could help me the following situation.
The following code is working fine
-----
DECLARE @.doc varchar(2000), @.hDoc int
DECLARE @.idoc int
SET @.doc =
'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ResultData>
<dat1>ResultCd</dat1>
<data2>ResultMessage</data2>
</ResultData>
</soap:Body>
</soap:Envelope>
'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />'
SELECT * FROM OPENXML(@.idoc, 'soap:Envelope/soap:Body/ResultData',2)
WITH
(
dat1 varchar(255),
data2 varchar(255)
)
EXEC sp_xml_removedocument @.idoc
-----
if I add another tag
<Websvc xmlns="http://tempuri.org/"> after <soap:Body> it is not working
after adding the above the code looks as follows
-----
DECLARE @.doc varchar(2000), @.hDoc int
DECLARE @.idoc int
SET @.doc =
'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Websvc xmlns="http://tempuri.org/">
<ResultData>
<dat1>ResultCd</dat1>
<data2>ResultMessage</data2>
</ResultData>
</Websvc>
</soap:Body>
</soap:Envelope>
'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />'
SELECT * FROM OPENXML(@.idoc, 'soap:Envelope/soap:Body/ResultData',2)
WITH
(
dat1 varchar(255),
data2 varchar(255)
)
EXEC sp_xml_removedocument @.idoc
-----
Thanks
Sai
hi Sai
what is the message that you see.
best Regards,
Chandra
http://www.SQLResource.com/
http://chanduas.blogspot.com/
*** Sent via Developersdex http://www.codecomments.com ***
|||Chandra
Thanks for your reply
The actual result I was expecting is
dat1 data2
ResultCdResultMessage
after I add the "<Websvc xmlns="http://tempuri.org/"> "
I am getting
dat1data2
(0 row(s) affected)
Thanks
Sai
"Chandra" wrote:

> hi Sai
> what is the message that you see.
> best Regards,
> Chandra
> http://www.SQLResource.com/
> http://chanduas.blogspot.com/
> *** Sent via Developersdex http://www.codecomments.com ***
>
|||It's because ResultData is now in the tempuri namespace and you've added a
node to the path that is now missing in your OPENXML statement. Change your
code to:
DECLARE @.doc varchar(2000), @.hDoc int
DECLARE @.idoc int
SET @.doc =
'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Websvc xmlns="http://tempuri.org/">
<ResultData>
<dat1>ResultCd</dat1>
<data2>ResultMessage</data2>
</ResultData>
</Websvc>
</soap:Body>
</soap:Envelope>
'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://tempuri.org/" />'
SELECT * FROM OPENXML(@.idoc,
'soap:Envelope/soap:Body/t:Websvc/t:ResultData',2)
WITH
(
dat1 varchar(255) 't:dat1',
data2 varchar(255) 't:data2'
)
EXEC sp_xml_removedocument @.idoc
Cheers,
Graeme
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
"Sai" <Sai@.discussions.microsoft.com> wrote in message
news:BB058093-023F-4CDA-B19C-31ADC9C7AF18@.microsoft.com...
Hi
I would appriciate if any one could help me the following situation.
The following code is working fine
-----
DECLARE @.doc varchar(2000), @.hDoc int
DECLARE @.idoc int
SET @.doc =
'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ResultData>
<dat1>ResultCd</dat1>
<data2>ResultMessage</data2>
</ResultData>
</soap:Body>
</soap:Envelope>
'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />'
SELECT * FROM OPENXML(@.idoc, 'soap:Envelope/soap:Body/ResultData',2)
WITH
(
dat1 varchar(255),
data2 varchar(255)
)
EXEC sp_xml_removedocument @.idoc
-----
if I add another tag
<Websvc xmlns="http://tempuri.org/"> after <soap:Body> it is not working
after adding the above the code looks as follows
-----
DECLARE @.doc varchar(2000), @.hDoc int
DECLARE @.idoc int
SET @.doc =
'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Websvc xmlns="http://tempuri.org/">
<ResultData>
<dat1>ResultCd</dat1>
<data2>ResultMessage</data2>
</ResultData>
</Websvc>
</soap:Body>
</soap:Envelope>
'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />'
SELECT * FROM OPENXML(@.idoc, 'soap:Envelope/soap:Body/ResultData',2)
WITH
(
dat1 varchar(255),
data2 varchar(255)
)
EXEC sp_xml_removedocument @.idoc
-----
Thanks
Sai
|||Graeme
Thanks a lot,that was a great solution.
I was trying for it for long time
I greately appriciate your time and help.
Sai
"Graeme Malcolm" wrote:

> It's because ResultData is now in the tempuri namespace and you've added a
> node to the path that is now missing in your OPENXML statement. Change your
> code to:
> DECLARE @.doc varchar(2000), @.hDoc int
> DECLARE @.idoc int
> SET @.doc =
> '<?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <Websvc xmlns="http://tempuri.org/">
> <ResultData>
> <dat1>ResultCd</dat1>
> <data2>ResultMessage</data2>
> </ResultData>
> </Websvc>
> </soap:Body>
> </soap:Envelope>
> '
> EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:t="http://tempuri.org/" />'
> SELECT * FROM OPENXML(@.idoc,
> 'soap:Envelope/soap:Body/t:Websvc/t:ResultData',2)
> WITH
> (
> dat1 varchar(255) 't:dat1',
> data2 varchar(255) 't:data2'
> )
> EXEC sp_xml_removedocument @.idoc
> Cheers,
> Graeme
>
> --
> Graeme Malcolm
> Principal Technologist
> Content Master
> - a member of CM Group Ltd.
> www.contentmaster.com
>
> "Sai" <Sai@.discussions.microsoft.com> wrote in message
> news:BB058093-023F-4CDA-B19C-31ADC9C7AF18@.microsoft.com...
> Hi
> I would appriciate if any one could help me the following situation.
> The following code is working fine
> -----
> DECLARE @.doc varchar(2000), @.hDoc int
> DECLARE @.idoc int
> SET @.doc =
> '<?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <ResultData>
> <dat1>ResultCd</dat1>
> <data2>ResultMessage</data2>
> </ResultData>
> </soap:Body>
> </soap:Envelope>
> '
> EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />'
> SELECT * FROM OPENXML(@.idoc, 'soap:Envelope/soap:Body/ResultData',2)
> WITH
> (
> dat1 varchar(255),
> data2 varchar(255)
> )
> EXEC sp_xml_removedocument @.idoc
> -----
> if I add another tag
> <Websvc xmlns="http://tempuri.org/"> after <soap:Body> it is not working
> after adding the above the code looks as follows
> -----
> DECLARE @.doc varchar(2000), @.hDoc int
> DECLARE @.idoc int
> SET @.doc =
> '<?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <Websvc xmlns="http://tempuri.org/">
> <ResultData>
> <dat1>ResultCd</dat1>
> <data2>ResultMessage</data2>
> </ResultData>
> </Websvc>
> </soap:Body>
> </soap:Envelope>
> '
> EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc,'<soap:Envelope
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />'
> SELECT * FROM OPENXML(@.idoc, 'soap:Envelope/soap:Body/ResultData',2)
> WITH
> (
> dat1 varchar(255),
> data2 varchar(255)
> )
> EXEC sp_xml_removedocument @.idoc
> -----
> Thanks
> Sai
>
>

OPENXML with dynamic SQL

I am trying to use OPENXML in a dynamic query and i guess its croaking becaause it starts a new thread and so it does not know about the file handle

any workaorounds

I can paste the snippet of code if needed

Thanks

To make it clear

sp_xml_prepare_document @.hdoc OUTPUT,@.doc

SET @. Insert =

'Insert into ..... select * from OPENXML(cast(@.hdoc as nvarchar(max) ......

Seems to give me a error on open xml

can some one help ?

Thanks

|||

You can pass the xml handle into sp_executesql.

e.g.

Code Snippet

DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
</Customer>
</ROOT>'

EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc

create table #tmp (CustomerID varchar(10),ContactName varchar(20))

insert #tmp
exec sp_executesql N'SELECT *
FROM OPENXML (@.idoc, ''/ROOT/Customer'',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))', N'@.idoc int',@.idoc

select * from #tmp

drop table #tmp

EXEC sp_xml_removedocument @.idoc

OpenXML with a schema

Why doesn't this work?
DECLARE @.xml VARCHAR(8000)
DECLARE @.iDoc INT
DECLARE @.Status INT
SELECT @.xml = '
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:updatable="true">
<s:AttributeType name="DocumentKey1" rs:number="1" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="DocumentKey1">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="DocumentKey2" rs:number="2" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="DocumentKey2">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="DocumentType" rs:number="3" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="DocumentType">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="SourceCompanyCode" rs:number="4" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="SourceCompanyCode">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="StarShipCompanyCode" rs:number="5"
rs:nullable="true" rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="StarShipCompanyCode">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:extends type="rs:rowbase"/>
</s:ElementType>
</s:Schema>
<rs:data>
<rs:insert>
<z:row DocumentKey1="172" SourceCompanyCode="SOA"/>
</rs:insert>
</rs:data>
</xml>
'
EXEC @.Status = sp_xml_preparedocument @.idoc OUTPUT, @.xml
SELECT 'sp_xml_preparedocument status=',@.Status
--SELECT * FROM OPENXML (@.idoc, '/xml',2)
select *
FROM OPENXML (@.idoc, '/xml/data/insert/row',4)
WITH(
DocumentKey1 varchar(30)'@.DocumentKey1'
,DocumentKey2 varchar(30)'@.DocumentKey2'
,DocumentType varchar(30)'DocumentType'
,SourceCompanyCodevarchar(30) '@.SourceCompanyCode'
,StarShipCompanyCodevarchar(30) '@.StarShipCompanyCode'
)
You need to declare the namespaces in sp_xml_preparedocument, and use their
prefixes in the XPath used in the OPENXML function:
EXEC @.Status = sp_xml_preparedocument @.idoc OUTPUT, @.xml, '<root
xmlns:z="#RowsetSchema" xmlns:rs="urn:schemas-microsoft-com:rowset"/>'
SELECT 'sp_xml_preparedocument status=',@.Status
--SELECT * FROM OPENXML (@.idoc, '/xml',2)
select *
FROM OPENXML (@.idoc, '/xml/rs:data/rs:insert/z:row',2)
WITH (
DocumentKey1 varchar(30) '@.DocumentKey1'
,DocumentKey2 varchar(30) '@.DocumentKey2'
,DocumentType varchar(30) 'DocumentType'
,SourceCompanyCode varchar(30) '@.SourceCompanyCode'
,StarShipCompanyCode varchar(30) '@.StarShipCompanyCode'
)
Hope that helps,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"John Grant" <johnwendell@.hotmail.com> wrote in message
news:B0134ADC-8D97-480C-A952-BA4862A7F75A@.microsoft.com...
Why doesn't this work?
DECLARE @.xml VARCHAR(8000)
DECLARE @.iDoc INT
DECLARE @.Status INT
SELECT @.xml = '
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:updatable="true">
<s:AttributeType name="DocumentKey1" rs:number="1" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="DocumentKey1">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="DocumentKey2" rs:number="2" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="DocumentKey2">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="DocumentType" rs:number="3" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="DocumentType">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="SourceCompanyCode" rs:number="4" rs:nullable="true"
rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="SourceCompanyCode">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:AttributeType name="StarShipCompanyCode" rs:number="5"
rs:nullable="true" rs:writeunknown="true" rs:basecatalog="StarShipServer"
rs:basetable="ShipmentKey" rs:basecolumn="StarShipCompanyCode">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
</s:AttributeType>
<s:extends type="rs:rowbase"/>
</s:ElementType>
</s:Schema>
<rs:data>
<rs:insert>
<z:row DocumentKey1="172" SourceCompanyCode="SOA"/>
</rs:insert>
</rs:data>
</xml>
'
EXEC @.Status = sp_xml_preparedocument @.idoc OUTPUT, @.xml
SELECT 'sp_xml_preparedocument status=',@.Status
--SELECT * FROM OPENXML (@.idoc, '/xml',2)
select *
FROM OPENXML (@.idoc, '/xml/data/insert/row',4)
WITH (
DocumentKey1 varchar(30) '@.DocumentKey1'
,DocumentKey2 varchar(30) '@.DocumentKey2'
,DocumentType varchar(30) 'DocumentType'
,SourceCompanyCode varchar(30) '@.SourceCompanyCode'
,StarShipCompanyCode varchar(30) '@.StarShipCompanyCode'
)

OPENXML with a namespace

Sorry, I've tried to search to find my answer, but I just can't quite figure
it out... I'm new to querying XML in a stored proc...
I have an XML file that looks like:
<Members xmlns="http://tempuri.org/template.xsd">
<Member>
<OperationType>Insert</OperationType>
</Member>
<Member>
<OperationType>Update</OperationType>
</Member>
</Members>
there's more to it, but I've simplified it down.
and in my stored proc, I'm trying this: (assume that @.idoc is already
declared and @.FileContents contains the contents of the xml file I'm
reading)
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.FileContents, '<Members
xmlns="http://tempuri.org/template.xsd"/>'
SELECT *
FROM OPENXML(@.idoc, '/Members/Member',2)
WITH (OperationType varchar(30))
EXEC sp_xml_removedocument @.idoc
I get no results...
If I take the xmlns declaration out of the <Members> element in the source
file, it works fine and I get a list of the OperationType elements.
What am I missing?
Thanks much,
SherylHi SL,
Welcome to the MSDN newsgroup.
Regarding on the OPENXML with namespace problem, based on my research, we
can use the third parameter of the sp_xml_prparedocument procedure to
specify namespace info. Also, in our sequental xpath, we need to explicitly
identify namespace through a namespace prefix. For detailed info, you can
refer to the following MSDN document and web article:
#How To: Use OpenXML on an Xml document with a default namespace
http://www.sqlxml.org/faqs.aspx?faq=101
#sp_xml_preparedocument
http://msdn.microsoft.com/library/e...o.asp?frame=tru
e
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||That was perfect, thanks!
"Steven Cheng[MSFT]" <stcheng@.online.microsoft.com> wrote in message
news:GubgkovKGHA.3680@.TK2MSFTNGXA02.phx.gbl...
> Hi SL,
> Welcome to the MSDN newsgroup.
> Regarding on the OPENXML with namespace problem, based on my research, we
> can use the third parameter of the sp_xml_prparedocument procedure to
> specify namespace info. Also, in our sequental xpath, we need to
> explicitly
> identify namespace through a namespace prefix. For detailed info, you can
> refer to the following MSDN document and web article:
>
> #How To: Use OpenXML on an Xml document with a default namespace
> http://www.sqlxml.org/faqs.aspx?faq=101
> #sp_xml_preparedocument
> http://msdn.microsoft.com/library/e...ft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>|||You're welcome SL,
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

OPENXML with a namespace

Sorry, I've tried to search to find my answer, but I just can't quite figure
it out... I'm new to querying XML in a stored proc...
I have an XML file that looks like:
<Members xmlns="http://tempuri.org/template.xsd">
<Member>
<OperationType>Insert</OperationType>
</Member>
<Member>
<OperationType>Update</OperationType>
</Member>
</Members>
there's more to it, but I've simplified it down.
and in my stored proc, I'm trying this: (assume that @.idoc is already
declared and @.FileContents contains the contents of the xml file I'm
reading)
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.FileContents, '<Members
xmlns="http://tempuri.org/template.xsd"/>'
SELECT *
FROM OPENXML(@.idoc, '/Members/Member',2)
WITH (OperationType varchar(30))
EXEC sp_xml_removedocument @.idoc
I get no results...
If I take the xmlns declaration out of the <Members> element in the source
file, it works fine and I get a list of the OperationType elements.
What am I missing?
Thanks much,
Sheryl
Hi SL,
Welcome to the MSDN newsgroup.
Regarding on the OPENXML with namespace problem, based on my research, we
can use the third parameter of the sp_xml_prparedocument procedure to
specify namespace info. Also, in our sequental xpath, we need to explicitly
identify namespace through a namespace prefix. For detailed info, you can
refer to the following MSDN document and web article:
#How To: Use OpenXML on an Xml document with a default namespace
http://www.sqlxml.org/faqs.aspx?faq=101
#sp_xml_preparedocument
http://msdn.microsoft.com/library/en...asp?frame=tru
e
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
|||That was perfect, thanks!
"Steven Cheng[MSFT]" <stcheng@.online.microsoft.com> wrote in message
news:GubgkovKGHA.3680@.TK2MSFTNGXA02.phx.gbl...
> Hi SL,
> Welcome to the MSDN newsgroup.
> Regarding on the OPENXML with namespace problem, based on my research, we
> can use the third parameter of the sp_xml_prparedocument procedure to
> specify namespace info. Also, in our sequental xpath, we need to
> explicitly
> identify namespace through a namespace prefix. For detailed info, you can
> refer to the following MSDN document and web article:
>
> #How To: Use OpenXML on an Xml document with a default namespace
> http://www.sqlxml.org/faqs.aspx?faq=101
> #sp_xml_preparedocument
> http://msdn.microsoft.com/library/en...asp?frame=tru
> e
> Hope this helps.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>
|||You're welcome SL,
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

OPENXML WHERE vs JOIN

i'm no sql expert by any means... can somebody please explain to me
which query is better and why
thanks
Query 1
--
SELECT top(1)
@.associationUid = SCUConversationPriority.AssociationUID,
@.retryCount = SCUConversationPriority.RetryCount
FROM SCUConversationPriority,
(SELECT [Name] FROM OPENXML (@.iDoc,'/Allowed/Route') WITH ([Name]
varchar(32))) [Route]
WHERE SCUConversationPriority.Status = @.getStatus AND
SCUConversationPriority.RouteName = [Route].[Name]
ORDER BY
Priority desc,
StatusTimeStamp;
Query 2
--
SELECT top(1)
@.associationUid = SCUConversationPriority.AssociationUID,
@.retryCount = SCUConversationPriority.RetryCount
FROM SCUConversationPriority JOIN
(SELECT [Name] FROM OPENXML (@.iDoc,'/Allowed/Route') WITH ([Name]
varchar(32))) [Route]
ON SCUConversationPriority.RouteName = [Route].[Name]
WHERE SCUConversationPriority.Status = @.getStatus
ORDER BY
Priority desc,
StatusTimeStamp;
The value of the xml document is
DECLARE @.allowed as xml
SET @.allowed = N'<Allowed><Route Name="OINK_SCP_CT"/><Route
Name="OINK_SCP_CR"/></Allowed>'
Where idoc is
EXEC @.err = sp_xml_preparedocument @.idoc OUTPUT, @.allowed
Thanks in advanceCheck the execution plans. They will probably be the same, as your question
is essentially whether
to do joins using the more modern join syntax or the old style (which are th
e same, semantically -
for inner joins).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<bvbone69@.yahoo.com> wrote in message news:1147179841.865433.143510@.e56g2000cwe.googlegroup
s.com...
> i'm no sql expert by any means... can somebody please explain to me
> which query is better and why
> thanks
> Query 1
> --
> SELECT top(1)
> @.associationUid = SCUConversationPriority.AssociationUID,
> @.retryCount = SCUConversationPriority.RetryCount
> FROM SCUConversationPriority,
> (SELECT [Name] FROM OPENXML (@.iDoc,'/Allowed/Route') WITH ([Name]
> varchar(32))) [Route]
> WHERE SCUConversationPriority.Status = @.getStatus AND
> SCUConversationPriority.RouteName = [Route].[Name]
> ORDER BY
> Priority desc,
> StatusTimeStamp;
> Query 2
> --
> SELECT top(1)
> @.associationUid = SCUConversationPriority.AssociationUID,
> @.retryCount = SCUConversationPriority.RetryCount
> FROM SCUConversationPriority JOIN
> (SELECT [Name] FROM OPENXML (@.iDoc,'/Allowed/Route') WITH ([Name]
> varchar(32))) [Route]
> ON SCUConversationPriority.RouteName = [Route].[Name]
> WHERE SCUConversationPriority.Status = @.getStatus
> ORDER BY
> Priority desc,
> StatusTimeStamp;
> The value of the xml document is
> DECLARE @.allowed as xml
> SET @.allowed = N'<Allowed><Route Name="OINK_SCP_CT"/><Route
> Name="OINK_SCP_CR"/></Allowed>'
> Where idoc is
> EXEC @.err = sp_xml_preparedocument @.idoc OUTPUT, @.allowed
> Thanks in advance
>

openxml vs xquery behind the scenes ?

Also, with regards the changes from Sql 2000 to Sql 2005.

When dealing with parsing/querying xml within a stored procedure, what is the difference (internally to sql server) between using OPENXML and xquery statements within a stored procedure ? With openxml, you need to call sp_xml_preparedocument, which will load a special version of the msxml parser called msxmlsql and loads the entire document into memory.

One thing that I like about XQUERY is that you can use the CROSS APPLY join to process database XML data on a row by row basis. I am new to using XML so I am also interested in hering the answer.