473,654 Members | 3,082 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 6702
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
4110
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? I can't find this reported anywhere else. I may just have to code around it. Details: link is created by the following code: <a>href="GroupDetails.asp?groupName=<%=Server.URLEncode(objRecordset("Group_Name"))%>">Group Details</a> If...
3
26522
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 following error: ---------------------------------------------------------------------------- ------------------------------------------------ Parser Error Message: This is an unexpected token. The expected token is 'SEMICOLON'. Line 70,...
1
5913
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 beginning but that didnt fix it. What am I missing?
4
2743
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
1103
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> but when this value is passed to browser the address bar shows http://lxg/lxgaming/browse.php?showing=50%26order%3D%26type%3D%26owner%3D%26page%3D1 means that ampersand is converted to (%26) without brackets and i think '$' is also converted to...
3
6655
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=" & HTTPUtility.URLEncode("500 Rt 6 & 209") and then to retrieve it: txtAddress1.text = Request.Querystring("AD1") However, in a different page of code, I loop through the QueryString.AllKeys collection like this:
13
5350
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, telling me that it should be: http://localhost:2063/Client/ViewReport.aspx?Ref=58&amp;Type=SUMMARY see: <http://www.htmlhelp.com/tools/validator/problems.html#amp>
0
2450
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 pointers and using them yet. Here is my program: #include <stdio.h> int main() { char yourname; int yourworth;
4
4209
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 is my code: ---------------- <body> <div id='div1'></div> <script>
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2709
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 we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.