|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
March 4th, 2004, 01:04 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
For XML Explicit
Hello,
I want to create XML explicitly as follows:
<Documents>
<Document>
<Name>
<Path>
</Document>
...
</Documents>
I am working with the query below, as was given me by an example, which I converted to this new syntax:
select 1 as tag,
NULL as parent,
Name as [Document!1!Name!element],
Path as [Document!1!Path!element]
from Documents
order by Name
for xml explicit
Which creates the XML without the Documents root tag. How do I create that? I don't understand "FOR XML" at all.
Thanks,
Brian
__________________
Brian
|
March 5th, 2004, 04:50 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I assume you're using ADO to get this XML back to your app? If so, you specify the root node as a property of the ADO command object. Here's a snippet of VB code for getting the results of a FOR XML query into a stream object:
Code:
' code here to open a connection named "con"
Set strm = New ADODB.Stream
strm.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandText = "stored proc name"
cmd.CommandType = adCmdStoredProc
cmd.Properties("Output Stream") = strm ' specify the output stream
cmd.Properties("XML Root") = "Documents" 'specify the root node here
' add any parameters here
cmd.Execute , Options:=adExecuteStream ' use this option
MsgBox strm.ReadText ' to access the XML string
If you want to load it into an XML DOM, you may be able to specify a DOM object as the "Output Stream" instead. I've never tried it myself - must give it a go sometime.
hth
Phil
|
March 5th, 2004, 05:05 AM
|
|
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Or, to encapsulate it all in a stored procedure, add
Code:
SET NOCOUNT ON
SELECT '<Documents>'
before your existing query and
Code:
SELECT '</Documents>'
SET NOCOUNT OFF
after it.
Joe (MVP - xml)
|
March 5th, 2004, 04:40 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
I'm using VBScript; what's the numerical equivalent to "adExecuteStream"?
Thanks for all of your help,
Brian
|
March 6th, 2004, 05:31 AM
|
|
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
If you are not including adovbs and are able to use the contstants then you can find out any value if you have Excel, Word or one of the other Office applications with VBA. Open a fresh document, go to VBA editor, normally Alt+F11, go to tools | references and check box next to Microsoft ActiveX Data Objects, version 2.5 or later. Okay box closed and press F2, in the dropdown change to ADODB and search for your term, alternatively open the immediate window and type
--
Joe
|
March 8th, 2004, 09:18 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
1024
|
|
|