?
Solved

Apostrophe in data used in sp_xml_preparedocument statement

Posted on 2007-10-05
5
Medium Priority
?
297 Views
Last Modified: 2008-02-01
SQL 2000
I have bad chars, go figure :), from user input off the web.  I have the trademark  sign as well a ' marks a plenty.

I am stumped in getting rid of the apostrophe in some text that may have 5 + marks.

This is the syntax that I'm using:
set @doc = (select replace( @doc, '''', '"'))
set @doc = (select replace( @doc, '&', '&'))


But here is the finished @doc that fails after the above code.

<specialInstruction><section =20
id=3D"customerSuppliedShippingAccount"></section><section =20
id=3D"customerCare">Please add the following to each recipient's =20
package:    1)  2 "Be Progressive" Holograms (8.5x11) must be in each =20
recipient=92s package.  2) 1   Smith &amp; Nephew Group CD per order =20
recipient</section><section id=3D"finance"></section><section =20
id=3D"production.general">Please add the following to each recipient's =20
package:    1)  2 "Be Progressive" Holograms (8.5x11) must be in each =20
recipient=92s package.  2) 1   Smith &amp; Nephew Group CD per order =20
recipient</section><section =20
id=3D"production.inventory"></section><section =20
id=3D"production.packaging">Please add the following to each recipient's =20
package:    1)  2 "Be Progressive" Holograms (8.5x11) must be in each =20
recipient=92s package.  2) 1   Smith &amp; Nephew Group CD per order =20
recipient</section><section =20
id=3D"production.prePress"></section><section =20
id=3D"production.printJob"></section><section =20
id=3D"production.shipping"></section></specialInstruction>

I could do multiple statements to hit each char one at a time.

set @loc = (SELECT CHARINDEX('''', @doc) )
if @loc  > 0
   begin
   set @doc = substring(@doc, 1, @loc -1) + substring(@doc ,  @loc +1, len(@doc))
end

But when I have 10 of them the user will need to use 12.  :)

What is a better way?

TIA
0
Comment
Question by:srussell705
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
dbbishop earned 1400 total points
ID: 20022631
Haven't worked much with XML, but does:
set @doc = (select replace( @doc, '&apos;', "'"))

work?
0
 
LVL 15

Expert Comment

by:dbbishop
ID: 20022675
You can also use &copy; (c) &reg; (r) and &tm; (tm)
0
 
LVL 14

Assisted Solution

by:twoboats
twoboats earned 600 total points
ID: 20022676
Thinking of some form of regular expression... along lines of

replace (@doc, '%[a-z0-9 ]''[a-z0-9 ], '"')

0
 
LVL 14

Expert Comment

by:twoboats
ID: 20022683
that's missing a close qutoe or so... ;)
0
 
LVL 1

Author Comment

by:srussell705
ID: 20023282
Here were some of the little fish I was trolling for:

set @doc = (select Replace(@doc,'ú','u'))
set @doc = (select Replace(@doc,'',''))
set @doc = (select Replace(@doc,'',''))
set @doc = (select Replace(@doc,'',''))
set @doc = (select Replace(@doc,'',' '))
set @doc = (select Replace(@doc,'½','1/2'))
set @doc = (select Replace(@doc,'¼','1/4'))

My trick for finding the offending chars was to print the @doc before the prepreXML statement.

I then pasted that text into an xml file and opened the XML in IE.  IE explains the position of the burp, so it took quite a few runs at this.  I didn't show all that I was looking for above.    
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

840 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