473,396 Members | 1,891 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,396 software developers and data experts.

strip

Let's say you are storing lots of URLs in XML files. So, for those with
non-XML-compliant characters you use the <![CDATA]]> construct ...

<Element1><![CDATA[http://overthetop.com?search=too%20much&sort=populatity]]></Element1>

Does .NET provide an intrinsic function that will strip the URL out of the
<![CDATA]]> construct ?
Apr 14 '06 #1
3 1927
<"John A Grandy" <johnagrandy-at-yahoo-dot-com>> wrote:
Let's say you are storing lots of URLs in XML files. So, for those with
non-XML-compliant characters you use the <![CDATA]]> construct ...

<Element1><![CDATA[http://overthetop.com?search=too%20much&sort=populatity]]></Element1>

Does .NET provide an intrinsic function that will strip the URL out of the
<![CDATA]]> construct ?


What do you mean by "strip" here?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 14 '06 #2
I am going to assume your are talking about the & character in the URL.
The & character is only used as an escape character within xml and
needs to be replaced with &amp; to be legal.

Your sample URL becomes
<Element1>http://overthetop.com?search=too%20much&amp;sort=populati ty</Element1>,
which is valid XML and cam be used as is for hyperlinks.

Here is some sample code to replace & in a URL with &amp;

public static void ReplaceRegex()
{
// Regex search and replace
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"&", options);
string input =
@"http://overthetop.com?search=too%20much&sort=populatity";
string replacement = @"&amp;";
string result = regex.Replace(input, replacement);

// TODO: Do something with result
System.Windows.Forms.MessageBox.Show(result, "Replace");
}

Apr 14 '06 #3
Yeah, I know, I tried that solution. The problem is that other people keep
on updating the config files with new URLs and not replacing "&" with
"&amp;" ..

Anyway, I figured out the answer ;

use XmlNode.InnerText instead of XmlNode.InnerXml
"The Other Nice Man" <ot**********@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
I am going to assume your are talking about the & character in the URL.
The & character is only used as an escape character within xml and
needs to be replaced with &amp; to be legal.

Your sample URL becomes
<Element1>http://overthetop.com?search=too%20much&amp;sort=populati ty</Element1>,
which is valid XML and cam be used as is for hyperlinks.

Here is some sample code to replace & in a URL with &amp;

public static void ReplaceRegex()
{
// Regex search and replace
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"&", options);
string input =
@"http://overthetop.com?search=too%20much&sort=populatity";
string replacement = @"&amp;";
string result = regex.Replace(input, replacement);

// TODO: Do something with result
System.Windows.Forms.MessageBox.Show(result, "Replace");
}

Apr 14 '06 #4

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

Similar topics

6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
2
by: Gustavo Randich | last post by:
Hello, (Using DB2/LINUX 8.2.0) After compiling the STRIP migration UDF (found at http://www-106.ibm.com/developerworks/db2/library/samples/db2/0205udfs/), if I try to execute: values...
5
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or...
6
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious......
4
by: Steve | last post by:
Hi, I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you...
6
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
7
by: Nick | last post by:
strip() isn't working as i expect, am i doing something wrong - Sample data in file in.txt: 'AF':'AFG':'004':'AFGHANISTAN':'Afghanistan' 'AL':'ALB':'008':'ALBANIA':'Albania'...
3
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed....
6
by: Christoph Zwerschke | last post by:
In Python programs, you will quite frequently find code like the following for removing a certain prefix from a string: if url.startswith('http://'): url = url Similarly for stripping...
4
by: Poppy | last post by:
I'm using versions 2.5.2 and 2.5.1 of python and have encountered a potential bug. Not sure if I'm misunderstanding the usage of the strip function but here's my example. var = "detail.xml"...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.