Can you please tell me what is the best way to get the XML file with the Tile in the first row as:
<?xml version="1.0" encoding="ISO-8859-15" ?>
and then the data rows?
The SQL query I am using is at the end of this post.
SSIS is some thing like this:
- Execute SQL with the query attached and mapping the result set to a variable.
- Using Script task for adding the Title in the first row.
I guess in the SQL, when I comment these two rows, the SQL runs and converts the output to XML:
depgate as DepartingGate,
arrgate as ArrivalGate,
If I dont comment the above rows, I am getting an error. The error message I am getting is:
Msg 9420, Level 16, State 1, Line 4 XML parsing: line 1, character 439, illegal xml character.
I tried restricting the & and -, etc. but it didn't work.
I saw the table and it is having some of the illegal characters for XML, but I am not sure how can I restrict these characters. Can you tell me what should be a good fix for this?
DECLARE @XmlOutput XML
set @XmlOutput = (
select
sched_local_fltdate as FlightDate,
flt_num as FlightNumber,
Dep as Origin,
Arr as Destination,
ltrim(rtrim(substring(ac, 2, 10))) as AccountNumber,
ac as RegisttrationNumber,
actype,
CASE WHEN cancelled = 'Y' then 'Cancelled'
when flight_type = 'S' then 'Scheduled'
when flight_type = 'O' then 'Spare Block'
when flight_type = 'C' then 'Charter'
when flight_type = 'F' then 'Ferry'
when flight_type = 'M' then 'Military'
when flight_type = 'SR' then 'Re-route'
when flight_type = 'X' then 'Maintenance Block'
else LTRIM(RTRIM(flight_type))
end as FlightTypeDescription,
case when cancelled = 'Y' then 'Cancelled'
when VPART_BLON > 0 then 'Arrived'
when flight_type in ('O','X') then 'No Flight'
end as FlightStatusDescription,
out_utc as OutUTMS,
in_utc as InUTMS,
depgate as DepartingGate,
arrgate as ArrivalGate,
departure_fuel_lbs as DepartureFuelLBS,
arrival_fuel_lbs as ArrivalFuelLBS,
'N/A' as FuelUnitOfMSRName
from [dbo].[ufn_Get_Flight_Operations_Base_Dataset] (cast(dateadd(day, -2, getdate()) as date), cast(getdate() as date), DEFAULT, DEFAULT, DEFAULT)
for xml Path('row'), elements)
Select @XmlOutput as XMLValue