Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Wanted: Simple query->DOM example

 
   Database Help (Home) -> XML RSS
Next:  Shaping this query  
Author Message
Siegfried Heintze

External


Since: Apr 21, 2008
Posts: 5



(Msg. 1) Posted: Tue Aug 05, 2008 9:32 am
Post subject: Wanted: Simple query->DOM example
Archived from groups: microsoft>public>sqlserver>xml (more info?)

Can someone point me to database neutral (i.e., works with MSAccess and SQL
Server) example that populates a DOM from a SQL SELECT statement?

Thanks,
Siegfried

 >> Stay informed about: Wanted: Simple query->DOM example 
Back to top
Login to vote
Bob

External


Since: Feb 08, 2005
Posts: 164



(Msg. 2) Posted: Wed Aug 06, 2008 1:21 am
Post subject: RE: Wanted: Simple query->DOM example [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I'm not sure what you mean by "populates a DOM", as to me, DOM is an API with
which you can manipulate XML. If you post some DDL, sample data and expected
results, maybe we can help a bit more.

I think you might mean an xsd, so I've scripted out a simple example for SQL
2005. "Language neutral" would be very difficult as SQL 2005 offers great
XML support, with FOR XML and OPENXML and the xml datatype. I don't think
Access offers any of these, at least not in the same way, so it would be
difficult to reproduce the results below without writing custom VBA code.

-- SQL 2005 example, prints xsd and XML
SET NOCOUNT ON

DROP TABLE #users
GO
CREATE TABLE #users ( user_id INT PRIMARY KEY, user_name VARCHAR(10),
date_added DATETIME DEFAULT(GETDATE()) )
GO
DROP TABLE #skills
GO
CREATE TABLE #skills ( skill_id INT PRIMARY KEY, skill_name VARCHAR(20),
date_added DATETIME DEFAULT(GETDATE()) )
GO
DROP TABLE #user_skills
GO
CREATE TABLE #user_skills ( user_skill_id INT IDENTITY UNIQUE, user_id INT,
skill_id INT, date_added DATETIME DEFAULT(GETDATE()), PRIMARY KEY ( user_id,
skill_id ) )
GO

INSERT INTO #users ( user_id, user_name ) VALUES ( 1, 'Siegried' )
INSERT INTO #users ( user_id, user_name ) VALUES ( 2, 'wBob' )

INSERT INTO #skills ( skill_id, skill_name ) VALUES ( 100, 'Access' )
INSERT INTO #skills ( skill_id, skill_name ) VALUES ( 101, 'SQL' )
INSERT INTO #skills ( skill_id, skill_name ) VALUES ( 102, 'XML' )
INSERT INTO #skills ( skill_id, skill_name ) VALUES ( 103, 'DOM' )

INSERT INTO #user_skills ( user_id, skill_id ) VALUES ( 1, 100 )
INSERT INTO #user_skills ( user_id, skill_id ) VALUES ( 2, 101 )
INSERT INTO #user_skills ( user_id, skill_id ) VALUES ( 2, 102 )
GO

SELECT u.user_id, u.user_name, s.skill_id, s.skill_name
FROM #user_skills us
INNER JOIN #users u ON us.user_id = u.user_id
INNER JOIN #skills s ON us.skill_id = s.skill_id

-- Auto
SELECT u.user_id, u.user_name, s.skill_id, s.skill_name
FROM #user_skills us
INNER JOIN #users u ON us.user_id = u.user_id
INNER JOIN #skills s ON us.skill_id = s.skill_id
FOR XML AUTO, XMLSCHEMA
-- Other sample options
--FOR XML RAW, XMLSCHEMA
--FOR XML RAW, ELEMENTS, XMLSCHEMA

HTH
wBob
"Siegfried Heintze" wrote:

> Can someone point me to database neutral (i.e., works with MSAccess and SQL
> Server) example that populates a DOM from a SQL SELECT statement?
>
> Thanks,
> Siegfried

 >> Stay informed about: Wanted: Simple query->DOM example 
Back to top
Login to vote
Ian Boyd3

External


Since: Sep 23, 2003
Posts: 113



(Msg. 3) Posted: Thu Aug 07, 2008 11:45 am
Post subject: Re: Wanted: Simple query->DOM example [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> Can someone point me to database neutral (i.e., works with MSAccess and
> SQL
> Server) example that populates a DOM from a SQL SELECT statement?

i think what you want is not an SQL Server question, but an ADO question.

And you want to call
Recordset.Save(xmlDocumentObject, adPersistXML);

which will save the contents of an ADO recorset to an XML document object.

And it's database independant, as it's ADO creating the XML, not Access or
SQL Server.
 >> Stay informed about: Wanted: Simple query->DOM example 
Back to top
Login to vote
Michael Coles

External


Since: May 29, 2008
Posts: 55



(Msg. 4) Posted: Sun Aug 10, 2008 12:46 am
Post subject: Re: Wanted: Simple query->DOM example [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

As Ian pointed out if you want a database-neutral DOM you need to create it
outside the database. The disadvantage of this is that you lose the ability
to manipulate your XML via SQL Server's enhanced XML capabilities in the
process (SQL 2005 and up), since it stores XML as a binary representation of
the XDM instead of DOM. You also lose the ability to index your XML on SQL
Server. To manipulate your XML in SQL Server 2005+ you will need to convert
from the DOM format back to string format, send it to SQL Server to be
converted to XDM format, and then shredded to relational format. In 2000
it's just as bad, but not as easy. There will be a lot of extra
overhead--keep in mind that poor performance is often the cost of
platform-neutrality.

--

========
Michael Coles
"Pro T-SQL 2008 Programmer's Guide"
http://www.amazon.com/T-SQL-2008-Programmer-rsquo-Guide/dp/143021001X


"Siegfried Heintze" <SiegfriedHeintze.DeleteThis@discussions.microsoft.com> wrote in
message news:69E56F61-3097-4224-95D8-0A4FA72DBC6E@microsoft.com...
> Can someone point me to database neutral (i.e., works with MSAccess and
> SQL
> Server) example that populates a DOM from a SQL SELECT statement?
>
> Thanks,
> Siegfried
 >> Stay informed about: Wanted: Simple query-&gt;DOM example 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]