473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ampersand in value gives me a pain

RD
Some of the customers in the table I'm trying to see in an XML doc have an
ampersand in the data. Looking at them and formatting the XML doc with a
style sheet this generates an error. I'm creating the XML doc with VB.Net
code, simply writing extracted values from my database to the XML doc. What
do I have to do so that the ampersands in the data does not create problems
while viewing the XML?

Any help would b egreatly appreciated.

Bob.
Nov 12 '05 #1
2 6686
You have to write an EscapeForXml() function in your VB program that
accepts a string from your database and returns a string ready to
insert into XML.

Your function should make the following transformations to whatever
string you pass it:

The '<' character should be written out as &lt; -- that's ampersand,
el, tee, semicolon.
The '>' character should be written out as &gt;
The double-quote character " should be written out as &quot;
The single-quote character ' should be written out as &apos;
The ampersand character & should be written out as &amp;

Every other printable ASCII character can be left as it is. If your
database strings contain control characters or characters about value
127 then you may want to filter them out. Otherwise you have to specify
the character set in your XML header.

(In fact you don't _really_ need to escape the single quote character
to &apos;, but it doesn't hurt.)

Nov 12 '05 #2
You could also enclose the data in the element in a CDATA section:

<foo><![CDATA[me & you]]></foo>

There are some utility methods, such as HTMLEncode() but you need an HTTP
context for this, and the OP hasn't said what the environment is.

Regards,
Mike Sharp
"Bruce Wood" wrote:
You have to write an EscapeForXml() function in your VB program that
accepts a string from your database and returns a string ready to
insert into XML.

Your function should make the following transformations to whatever
string you pass it:

The '<' character should be written out as < -- that's ampersand,
el, tee, semicolon.
The '>' character should be written out as >
The double-quote character " should be written out as "
The single-quote character ' should be written out as &apos;
The ampersand character & should be written out as &

Every other printable ASCII character can be left as it is. If your
database strings contain control characters or characters about value
127 then you may want to filter them out. Otherwise you have to specify
the character set in your XML header.

(In fact you don't _really_ need to escape the single quote character
to &apos;, but it doesn't hurt.)

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4095
by: debk | last post by:
Server.UrlEncode is not longer converting the ampersand in a string to %26 so the value passed in the querystring gets truncated in the following page. Is this a problem with IIS, does anyone know?...
3
26438
by: Eidolon | last post by:
I am wondering how i can put an ampersand character into the value attribute of a key in the appSettings section of my web.config file. If i try to simply type it in, then run my web app, i get the...
1
5897
by: klynn | last post by:
I have a web.config key as follows: <add key="DOC_TRAILER" value="&Lib=whatever&File=.pdf&Frameset=Created" /> but I cant run the app with this string. Problems with & I tried putting @ at...
4
2729
by: frizzle | last post by:
Hi there, Recently i noticed a few times an ampersand in front of a variable in a function. Like so: function foo( &$bar ) { // do something };
0
1083
by: lxgamer | last post by:
hello every one here i'm trying to do the following <option value="<?php echo "50&order=$order&type=$type&owner=$owner&page=$page"; ?>" <?php if($showing=="50") echo "selected"; ?>>50</option> ...
3
6648
by: Elroyskimms | last post by:
I have to encode an address which contains an ampersand (&) into a URL with various querystring parameters. The following code works fine: URLString = "www.myserver.com?AD1=" &...
13
5330
by: mark4asp | last post by:
When I write a url in xhtml, with an unencoded ampersand, like this: http://localhost:2063/Client/ViewReport.aspx?Ref=58&Type=SUMMARY the xhtml sytax checker correctly indicates an error,...
0
2441
by: vlsidesign | last post by:
I am a newbie to C, and was hoping to get a little bit better handle on this until I get deeper into pointers, etc. I kind of understand it some, but still unfamiliar because I haven't got to...
4
4194
by: Kiran Makam | last post by:
I am setting the content of a div dynamically using innerHTML property. If the content contains an ampersand, text after the ampersand is disappearing in IE6. It works properly in Firefox. This...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.