Re: OPENXML to accept both attributes and elements
- From: Martin Honnen <mahotrash@xxxxxxxx>
- Date: Mon, 09 Feb 2009 19:12:08 +0100
Goran Djuranovic wrote:
Is it possible to retreive values from XML document whether they where sent as elements or attributes, using OPENXML?
For example, if someone sends me:
<Root><Customer Name="blah"></Customer></Root> or
<Root><Customer><Name>blah</Name></Customer></Root>
I want to be able to read both. Possible?
I am not sure about OPENXML but XQuery can do it:
DECLARE @doc XML;
SET @doc = N'<Root><Customer Name="Foo"></Customer><Customer><Name>Bar</Name></Customer></Root>';
SELECT
T.c.value('(@Name, Name)[1]', 'nvarchar(20)') AS [Name]
FROM
@doc.nodes('Root/Customer') AS T(c);
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.
- Follow-Ups:
- Re: OPENXML to accept both attributes and elements
- From: Goran Djuranovic
- Re: OPENXML to accept both attributes and elements
- References:
- OPENXML to accept both attributes and elements
- From: Goran Djuranovic
- OPENXML to accept both attributes and elements
- Prev by Date: OPENXML to accept both attributes and elements
- Next by Date: Re: OPENXML to accept both attributes and elements
- Previous by thread: OPENXML to accept both attributes and elements
- Next by thread: Re: OPENXML to accept both attributes and elements
- Index(es):