473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1471


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 exampleURLWithQueryString =
@"http://example.com/whoisgod?name=Kibo&domain=usenet";

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.AppendChild(xmlDocument.CreateElement( "example"));
xmlDocument.DocumentElement.SetAttribute("link",
exampleURLWithQueryString);
xmlDocument.DocumentElement.AppendChild(
xmlDocument.CreateTextNode(exampleURLWithQueryStri ng)
);

xmlDocument.Save(Console.Out);

will produce the markup

<example
link="http://example.com/whoisgod?name=Kibo&amp;domain=usenet">http://example.com/whoisgod?name=Kibo&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 exampleURLWithQueryString =
@"http://example.com/whoisgod?name=Kibo&domain=usenet";

XmlTextWriter xmlWriter = new XmlTextWriter(Console.Out);
xmlWriter.WriteStartElement("example");
xmlWriter.WriteAttributeString("link", exampleURLWithQueryString);
xmlWriter.WriteString(exampleURLWithQueryString);
xmlWriter.WriteEndElement();
xmlWriter.Close();
gives the serialized markup

<example
link="http://example.com/whoisgod?name=Kibo&amp;domain=usenet">http://example.com/whoisgod?name=Kibo&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
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...
14
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;...
2
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? ...
4
by: weirdstuff | last post by:
Hi. I have this simple code: =========================================== ->Database query here (.. some code) $row=mysql_fetch_array($res); (...)
2
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"...
12
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 -...
2
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...
12
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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...
0
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
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...
0
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,...
0
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...

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.