Responses inline...
Quote:> Hello Mike:
> Greetings and thank you so very much for your - MOST
> PROMPT - reply. I truly appreciate it a whole lot more
> than I can express.
> First, about the error message. I was goofy ... skipping
> the FOR XML AUTO in my query. When I realized that and
> made the necessary correction, my query worked just fine
> in the url!
> Now 2 other questions (if you can forgive me for all my
> questions!)
> 1. How can I get the effect of FOR EXPLICIT since I am
> getting a whole row in the current result set, in other
> words, instead of, for each element separately.
Well, you can modify the tagnames by using aliases in your query, such as
Select fname as GivenName, lname as Surname from Authors for XML AUTO
This will produce:
<Authors GivenName="Mike" Surname="Sharp"/>
If you want the values as child elements, just modify the FOR XML AUTO to
look like:
FOR XML AUTO, ELEMENTS
which changes the XML output to look like:
<Authors>
<GivenName>Mike</GivenName>
<Surname>Sharp</Surname>
</Authors>
Quote:> 2. Coming back to your original reply (step # 13,
> *temporary *), how would I accomplish all this in a non-
> url-way (so that there would be no security issues, at
> least as far as the url-way is concerned. Since, I know
> that it is working now.)
There are several ways, but I like using templates. You can read about them
on BOL, and in the SQLXML documentation, but essentially you create a
virtual name in the same virtual directory managment snap-in (the Virtual
Names tab).
So, I create a subfolder under my vpubs folder (using Windows Explorer).
Then I create a new virtual name, called for example, "template"
From the drop-down, I select "Template"
I browse to the folder I created previously, which enters the path to the
Template folder.
I click Save.
Now I create an XML document and put it in that folder, saving it as
"authorlist.xml". The XML document might look like:
<?xml version="1.0" encoding="UTF-8"?>
<Author xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:query>
SELECT
a.au_fname,
a.au_lname,
p.pub_name
FROM
authors AS a
RIGHT OUTER JOIN
publishers AS p
ON
a.city = p.city
ORDER BY
p.pub_name ASC,
a.au_lname ASC,
a.au_fname ASC
FOR XML AUTO, ELEMENTS
</sql:query>
</Author>
I get the XML by simply using the URL of the template I just created.
http://localhost/vpubs/template/authorlist.xml
You must use IIS to get the template--you can't for example use:
c:\inetpub\wwwroot\vpubs\template\authorlist.xml
You can actually put all this code in a stored procedure, which is better,
and call the sproc from the template, like:
<?xml version="1.0" encoding="UTF-8"?>
<LocReports xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:query>
EXECUTE sp_getAuthorList
</sql:query>
</LocReports>
You can even pass parameters in, like:
<?xml version="1.0" encoding="UTF-8"?>
<CustomerList xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:header>
<sql:param name="custID">%</sql:param>
</sql:header>
<sql:query>
SELECT
*
FROM
Customers
WHERE
FOR XML AUTO, ELEMENTS
</sql:query>
</CustomerList>
You use the template with a parameter like:
http://localhost/northwind/template/CustomerList.xml?custID=ALFKI
If you don't supply a parameter, the default of "%" is used.
Regards,
Mike Sharp
Quote:> Thanks again so very much.
> kishan