473,467 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

replace invalid xml characters

I know that System.Security.SecurityElement.Escape() will replace invalid
xml chars with valid equivalent ...

But is there another method to accomplish same that is "closer to home" ?
Apr 19 '06 #1
2 8103
* John A Grandy wrote:
I know that System.Security.SecurityElement.Escape() will replace invalid
xml chars with valid equivalent ...

But is there another method to accomplish same that is "closer to home" ?


I usually use the stream editor "sed" for this type of stuff.
Apr 20 '06 #2


John A Grandy wrote:
I know that System.Security.SecurityElement.Escape() will replace invalid
xml chars with valid equivalent ...

But is there another method to accomplish same that is "closer to home" ?


If you want to create XML with .NET then Xml(Text)Writer is the tool and
its methods will do all escaping necessary for you e.g.

XmlTextWriter xmlWriter = new XmlTextWriter(Console.Out);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("root");
xmlWriter.WriteElementString("text", "Kibo & Xibo");
xmlWriter.WriteElementString("comparison", "a < b");
xmlWriter.WriteEndDocument();
xmlWriter.Close();

will write

<root>
<text>Kibo &amp; Xibo</text>
<comparison>a &lt; b</comparison>
</root>

so everything is escaped as necessary.
If that does not help then tell exactly which kind of "invalid"
characters you have or maybe check first whether some of the other methods
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlTextWriterMethodsTopic.asp>
Xml(Text)Writer provides like WriteBase64 or WriteBinHex do what you need.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 20 '06 #3

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

Similar topics

7
by: WindAndWaves | last post by:
Hi Gurus I am a novice - just so you know. is there a smarter way to write: $keywords = str_replace("'", "",$keywords); $keywords = str_replace('"', '',$keywords); $keywords =...
14
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
4
by: Hardy Wang | last post by:
Hi: I have a XML like <?xml version="1.0" ?> <object> <comments>www.site.com/page.aspx?param1=value1&param2=value2</comments> </object> Since "&" is invalid in XML, I need to replace all "&"...
4
by: GregMa | last post by:
Does anyone have a good regex expression to replace any invalid filename characters in a string? Those characters are: /, \, :, *, ?, ", <, >, | I have it right now with string.replace for each...
5
by: cj | last post by:
I just ran across this in the VB help. Sounds perfect. Only they don't tell me what namespace must be imported to use regex. I guess that's the problem cause I pasted this into a test program...
4
by: vvenk | last post by:
Hello: I have a string, "Testing_!@#$%^&*()". It may have single and double quotations as well. I would like to strip all chararcters others than a-z, A-Z, 0-9 and the comma. I came across...
2
by: =?iso-8859-1?B?RnJhbiBHYXJj7WE=?= | last post by:
I've some text with some extended ascii characters like ¿ or ¡ and I wanna replace these characters for blanks, but when I use the function str_replace, it returns an invalid string, so I think...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
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
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.