|
Home > Archive > MS SQL XML > July 2005 > FOR XML AUTO, ELEMENTS
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
FOR XML AUTO, ELEMENTS
|
|
|
| Hi,
Is it possible to include an attribute within the dataset returned using FOR
XML AUTO, ELEMENTS ?
The format returned when using ELEMENTS is perfect for what I need but I
just need to make the ID field an attribute rather than an element.
Grateful for any advice.
Alex
| |
|
| I am not an expert, but according to the docs you cannot do that with
AUTO. You will need to do it with RAW.
| |
| Graeme Malcolm 2005-07-15, 7:23 am |
| Actually, RAW (in SQL Server 2000) will return everything as attributes, and
as I understand it you want a mix of attributes and elements. To do that
you'd need to use EXPLICIT mode, as in this example:
USE Northwind
SELECT 1 AS Tag,
NULL AS Parent,
ProductID AS & #91;Item!1!ProductID
],
ProductName AS & #91;Item!1!Name!elem
ent],
UnitPrice AS & #91;Item!1!Price!ele
ment]
FROM [Products]
FOR XML EXPLICIT
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
"ali" <ali.jan@gmail.com> wrote in message
news:1121413418.618949.238900@g14g2000cwa.googlegroups.com...
I am not an expert, but according to the docs you cannot do that with
AUTO. You will need to do it with RAW.
| |
| Graeme Malcolm 2005-07-15, 7:23 am |
| NB: I'm assuming you're using SQL Server 2000 - in SQL Server 2005 you could
use PATH mode.
--
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
"Graeme Malcolm" <graemem_cm@hotmail.com> wrote in message
news:O81hWwRiFHA.3544@TK2MSFTNGP15.phx.gbl...
Actually, RAW (in SQL Server 2000) will return everything as attributes, and
as I understand it you want a mix of attributes and elements. To do that
you'd need to use EXPLICIT mode, as in this example:
USE Northwind
SELECT 1 AS Tag,
NULL AS Parent,
ProductID AS & #91;Item!1!ProductID
],
ProductName AS & #91;Item!1!Name!elem
ent],
UnitPrice AS & #91;Item!1!Price!ele
ment]
FROM [Products]
FOR XML EXPLICIT
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
"ali" <ali.jan@gmail.com> wrote in message
news:1121413418.618949.238900@g14g2000cwa.googlegroups.com...
I am not an expert, but according to the docs you cannot do that with
AUTO. You will need to do it with RAW.
|
|
|
|
|