Monday, February 20, 2012

OPENXML question

I am using the OpenXml command and I have a question (XML posted below)...
I don't know how to get the values of certain elements if they columns
needed are not attributes to the XML...
For instance I can get the value of /attributes/items for the type attribute
but if I try to get the values of the /attributes/items/item elements it
returns null.
'<attributes>
<lot>E070484</lot>
<from-location type="dock">AA01</from-location>
<dest-location type="dock">AA05</dest-location>
<items type="yarn">
<item>QP35990</item>
<item>QP36134</item>
</items>
</attributes>'
JITry the following:
SELECT *
FROM OPENXML ( @.idoc, '/attributes/items/item',2 )
with
([Value] varchar(100) '.')
Q
"JI" wrote:

> I am using the OpenXml command and I have a question (XML posted below)...
> I don't know how to get the values of certain elements if they columns
> needed are not attributes to the XML...
> For instance I can get the value of /attributes/items for the type attribu
te
> but if I try to get the values of the /attributes/items/item elements it
> returns null.
> '<attributes>
> <lot>E070484</lot>
> <from-location type="dock">AA01</from-location>
> <dest-location type="dock">AA05</dest-location>
> <items type="yarn">
> <item>QP35990</item>
> <item>QP36134</item>
> </items>
> </attributes>'
>
> --
> JI|||Try,
use northwind
go
declare @.idoc int
declare @.doc varchar(1000)
set @.doc ='<attributes>
<lot>E070484</lot>
<from-location type="dock">AA01</from-location>
<dest-location type="dock">AA05</dest-location>
<items type="yarn">
<item>QP35990</item>
<item>QP36134</item>
</items>
</attributes>'
exec sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT
*
FROM
OPENXML (@.idoc, '/attributes/items/item')
with (item varchar(10) '/attributes/items/item')
EXEC sp_xml_removedocument @.idoc
"JI" wrote:

> I am using the OpenXml command and I have a question (XML posted below)...
> I don't know how to get the values of certain elements if they columns
> needed are not attributes to the XML...
> For instance I can get the value of /attributes/items for the type attribu
te
> but if I try to get the values of the /attributes/items/item elements it
> returns null.
> '<attributes>
> <lot>E070484</lot>
> <from-location type="dock">AA01</from-location>
> <dest-location type="dock">AA05</dest-location>
> <items type="yarn">
> <item>QP35990</item>
> <item>QP36134</item>
> </items>
> </attributes>'
>
> --
> JI

No comments:

Post a Comment