[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL Server XML Output

Posted on 2008-10-13
6
Medium Priority
?
1,063 Views
Last Modified: 2008-10-16
In my attached code...everything is pulling correctly, but I need the VERY first line to be

<?xml version="1.0" encoding="iso-8859-1" ?>

How do I modify my attached stored procedure
ALTER PROCEDURE [dbo].[XML_Reports]
 
AS
BEGIN
DECLARE @title XML 
SET @title = N'<?xml version="1.0" encoding="UTF-16" ?>'
 
DECLARE @link XML 
SET @link = N'<?xml version = "1.0" encoding = "UTF-16"?><link>http://www.mydomain.com</link>'
 
DECLARE @description XML 
SET @description = N'<?xml version = "1.0" encoding = "UTF-16"?><description>Current Real Estate Listings from My Domain Properties</description>'
 
DECLARE @lastBuildDate XML 
SET @lastBuildDate = N'<?xml version = "1.0" encoding = "UTF-16"?><feedPublishDate>' + CONVERT (Varchar(10), getdate(), 101) + '</feedPublishDate>'
 
DECLARE @language XML 
SET @language = N'<?xml version = "1.0" encoding = "UTF-16"?><language>en-us</language>'
 
select
--Non-Recurring header Section
(Select @title),
(Select @link),
(Select @description),
(Select @lastBuildDate),
(Select @language),
--Recurring Properties Section
(select [listing_id] as 'Listing_ID',
[property_type_id] as 'Property_Type_ID',
[newspaper_id] as 'Newspaper_ID',
null as 'House_Number',
[House_Street] as 'House_Street',
[Display_Address] as 'Display_Address',
[ZIP] as 'ZIP',
[rental_or_sale] as 'rental_or_Sale',
[price] as 'Price',
[Bedrooms_ID] as 'Bedrooms_ID',
[Agent_ID],
[Agent_Contact_1],
[Agent_Phone_1],
[Agent_Email_1],
[Agent_Picture_1],
[Comments],
[Full_baths],
[Acres],
[Listing_Photo_1],
[Listing_Photo_2],
[Listing_Photo_3],
[Listing_Photo_4],
[Listing_Photo_5],
[Listing_Photo_6],
[Listing_Photo_7]
from dbo.myView for xml path('ad'), type, elements
) 
FOR XML path('export')
END

Open in new window

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 80

Expert Comment

by:arnold
ID: 22703033
I suspect the issue is not with the stored procedure, but with the table/server definition of the character encoding. Make sure it is set to UTF rather then Latin1.
0
 

Author Comment

by:lrbrister
ID: 22703121
When I change the @titole to
SET @title = N'<?xml version="1.0" encoding="iso-8859-1" ?>'

I get this error on execute
Msg 9402, Level 16, State 1, Procedure XML_RSSOutRobbReports, Line 14
XML parsing: line 1, character 44, unable to switch the encoding
0
 

Author Comment

by:lrbrister
ID: 22703145
arnold:

How would I change that and what would it affect?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 80

Expert Comment

by:arnold
ID: 22703539
Misread what you wanted to achieve.

Is line 14:
SET @language = N'<?xml version = "1.0" encoding = "UTF-16"?><language>en-us</language>'

Check the encoding on the database/table?  I.e. what is the character set?  
Could you repost the SP after the changes are made?
0
 

Author Comment

by:lrbrister
ID: 22710429
arnold:
Where do I check that at?
0
 
LVL 80

Accepted Solution

by:
arnold earned 2000 total points
ID: 22712200
Properties of the database have the collation settings.  In your case however, I think the issue is with the directive.  If the line 14 noted in the error message is the language line, While you defined the content as ISO-8859-1 (LATIN1) you are trying to redefine the language to en-us which might be no be required or the Language directive is unnecessary.

Since it seems obvious I am trying to make sure that you altered all the <?XML references to use the ISO-8859-1 rather than just altering the title directive.
ALTER PROCEDURE [dbo].[XML_Reports]
 
AS
BEGIN
DECLARE @title XML 
SET @title = N'<?xml version="1.0" encoding="iso-8859-1" ?>'
 
DECLARE @link XML 
SET @link = N'<?xml version="1.0" encoding="iso-8859-1" ?><link>http://www.mydomain.com</link>'
 
DECLARE @description XML 
SET @description = N'<?xml version="1.0" encoding="iso-8859-1" ?><description>Current Real Estate Listings from My Domain Properties</description>'
 
DECLARE @lastBuildDate XML 
SET @lastBuildDate = N'<?xml version="1.0" encoding="iso-8859-1" ?><feedPublishDate>' + CONVERT (Varchar(10), getdate(), 101) + '</feedPublishDate>'
 
DECLARE @language XML 
SET @language = N'<?xml version="1.0" encoding="iso-8859-1"?><language>en-us</language>'
 
select
--Non-Recurring header Section
(Select @title),
(Select @link),
(Select @description),
(Select @lastBuildDate),
(Select @language),
--Recurring Properties Section
(select [listing_id] as 'Listing_ID',
[property_type_id] as 'Property_Type_ID',
[newspaper_id] as 'Newspaper_ID',
null as 'House_Number',
[House_Street] as 'House_Street',
[Display_Address] as 'Display_Address',
[ZIP] as 'ZIP',
[rental_or_sale] as 'rental_or_Sale',
[price] as 'Price',
[Bedrooms_ID] as 'Bedrooms_ID',
[Agent_ID],
[Agent_Contact_1],
[Agent_Phone_1],
[Agent_Email_1],
[Agent_Picture_1],
[Comments],
[Full_baths],
[Acres],
[Listing_Photo_1],
[Listing_Photo_2],
[Listing_Photo_3],
[Listing_Photo_4],
[Listing_Photo_5],
[Listing_Photo_6],
[Listing_Photo_7]
from dbo.myView for xml path('ad'), type, elements
) 
FOR XML path('export')
END

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question