473,799 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with URL characters to be saved in XML formatted doc.

Joe
I want to save some URLs into a XML formatted document.

I find out that its having some problems due to some of the characters
used
in the URL.

Is there a quick way to get around that? Thanks.

Here are some of the URL characters in the parameters

www.site.com/='N+Ss+Volume'& sym=

http://www2.site.com/

http://www.site.com/.?scanType=all_s...ange=all_&x=14


Are there any easy to use prewritten code to take care of this (the special
characters used in the URL I need to store in the XML formatted are causing
load and read problems with the XMLdocument object)?
Feb 5 '06 #1
1 1491


Joe wrote:
I want to save some URLs into a XML formatted document. Are there any easy to use prewritten code to take care of this (the special
characters used in the URL I need to store in the XML formatted are causing
load and read problems with the XMLdocument object)?


The character & needs to be escaped as & (& a m p ; for web forum
readers) but any of the XML tools will do that automatically if you put
it into a text node/content of an element or attribute e.g. the
following C# code

string exampleURLWithQ ueryString =
@"http://example.com/whoisgod?name=K ibo&domain=usen et";

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.App endChild(xmlDoc ument.CreateEle ment("example") );
xmlDocument.Doc umentElement.Se tAttribute("lin k",
exampleURLWithQ ueryString);
xmlDocument.Doc umentElement.Ap pendChild(
xmlDocument.Cre ateTextNode(exa mpleURLWithQuer yString)
);

xmlDocument.Sav e(Console.Out);

will produce the markup

<example
link="http://example.com/whoisgod?name=K ibo&amp;domain= usenet">http://example.com/whoisgod?name=K ibo&amp;domain= usenet</example>

so all ampersands are properly escaped as &amp; (& a m p ; for web readers).

Same if you use an XmlTextWriter e.g. the C# code

string exampleURLWithQ ueryString =
@"http://example.com/whoisgod?name=K ibo&domain=usen et";

XmlTextWriter xmlWriter = new XmlTextWriter(C onsole.Out);
xmlWriter.Write StartElement("e xample");
xmlWriter.Write AttributeString ("link", exampleURLWithQ ueryString);
xmlWriter.Write String(exampleU RLWithQueryStri ng);
xmlWriter.Write EndElement();
xmlWriter.Close ();
gives the serialized markup

<example
link="http://example.com/whoisgod?name=K ibo&amp;domain= usenet">http://example.com/whoisgod?name=K ibo&amp;domain= usenet</example>

Thus if you use the proper tools to create your XML then there should
not be a problem.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 5 '06 #2

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

Similar topics

1
9757
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no control. It outputs all text fields surrounded by quotes, and all numeric fields w/o quotes. All fields are separated with commas. This has been working for 2 years, until today, when one of the data fields
14
1820
by: beginner10 | last post by:
How can i changhe this code showing how many persons i saved to the file? And it prints pretty much rubbish. Where is the problem? #include <stdio.h> int main() { int i; FILE *data_file; char list = "list.txt";
2
1598
by: Joe | last post by:
Hi, I want to save some URLs into a XML formatted document. I find out that its having some problems due to some of the characters used in the URL. Is there a quick way to get around that? Thanks. Here are some of the URL characters in the parameters
4
3430
by: weirdstuff | last post by:
Hi. I have this simple code: =========================================== ->Database query here (.. some code) $row=mysql_fetch_array($res); (...)
2
5635
by: AmigoFd | last post by:
Hello, This problem is really driving me crazy ... * I have a mySql database which is latin1_swedish_ci * In my web.config I have: <globalization requestEncoding="ISO-8859-2" responseEncoding="ISO-8859-2" fileEncoding="iso-8859-2" culture="pl-PL" uiCulture="pl-PL" />
12
8465
by: Atlas | last post by:
I'm working on a multilanguage ASP/HTML site using a IIS6 web server. It perfectly works with two languages (english and italian) in this way: - basically the same ASP code for every language - language-specific content is stored in text files, every language has it's own directory contents. - to enhance usability and formatting the language-specific contents are stored with html syntax; basically the code that normally stands between...
2
3830
by: Big Moxy | last post by:
I want to send html formatted text yet strip out special characters (e.g. quotes and semi colons). I've seen preg_replace examples like $messageout = preg_replace('/\(\)<>]/i','',$message); to preserve some additional characters but don't know how to approach preserving html in general. This is a typical message line: $message.= "<b>Date: </b>" . $today . "<br />"; I am setting these headers:
12
9760
by: Punkis | last post by:
Hi all, I have a problem with my php and mysql project. I use an auctions software, named phpauction for my project. I import into my database with utf8 encodingm and I can see the greek letters inside the fields. The problem is that when i go to the site for the results, I get question marks instead of the greek characters. I have searched a lot, and i found that there is a solution by adding mysql_query("SET NAMES utf8") after...
4
1710
by: utab | last post by:
Dear all, I have to interface some C code in C++, but I had a problem with sscanf function, it has been some time I have not used C and I could not figure out my problem. Simple code is below, I am trying to read a file with line line 8 characters wide, 88888888 it has unix line ending LF, but I am getting a segfault from the sscanf
0
9688
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
9546
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
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.