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" ? 


0
John
4/19/2006 10:52:04 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
644 Views

Similar Articles

[PageSpeed] 14

* 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.
0
mr.flibble (10)
4/20/2006 9:38:52 AM

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/
0
mahotrash (1777)
4/20/2006 12:45:02 PM
Reply:

Similar Artilces:

Need help for a specific find & replace
Hi Everybody! I need to fill the spaces on some words with %20. Eg. D_010 SETMP2 KIT.jpg - before D_010%20SETMP2%20KIT.jpg - after I need to a replace in a whole column like that. How can I do that? And if possible, is there a way to make a macro for that or some way t make it like a 1 click procedure? Thanks a lo -- Message posted from http://www.ExcelForum.com Do an Edit | Replace... | Find what: " " (space, no quotes) and Replace with: "%20" (again, no quotes) | Replace All Regards Trevor "skuba >" <<skuba.14gw40@excelforum-nospam.com> w...

Word Template Character Encoding Issue
I am working on creating a letter mail merge template (usig Word 2007) for CRM Live. I have saved the file as a Word XML file and have uploaded. Everything works fine, except when I generate a new letter, apostrophes and quotation marks are rendered as codes rather than the normal characters. I'm assuming this is an encoding issue related to being stored in a SQL database and then re-rendered in Word. Is there a technique that I can use in my letter template files that will cause apostrophes and quotation marks to render correctly? I also have a similar problem with bullets, altho...

Altchunk replace with HTM content not working on Office 2003
When we replace Altchunk with content from an HTM file the same works fine on office 2007 but fails to open with the office 2003 compatibility pack. Is there any work around for the same ? ...

Saved CSV carraige return character
Hi all, I have exported some data to excel in tabular format and than I saved i as a csv file. I than open it using notepad and the details are in individual rows. May I know if anyone knows what is the special characters being used as a carraige return? Thanks David ...

Ado and Xpath vs. Ado.Net and XML
I am a newbie to Ado.Net. I am trying to convert my code to ado.net but I could not find equivalence. Could someone out there shed me a light. I had data in DB, I created a schema, retrieved data from Db based on the schema and display data in the same format as schema. I did that successfully with XPath Query in (old) Visual Basic but not with Ado.Net and VB.Net. (More explanation about this in MS knowledge Base article 271619) Thank you ======================================== Const DBGUID_XPATH As String = "{ec2a4293-e898-11d2-b1b7- 00c04f680c56}" Dim DbConn As New A...

Special Characters Are Being Replaced With A Square
I am using Outlook 2003 and compose my messages using HTML format. I am using MS Word 2003 to edit/read e- mails. When I create a message with special characters, such as apostrophe, quotation marks, exclamation marks, etc., they are replaced with a square. The message appears correct while I'm composing it, but once it's sent the change occurs. When the recipient replies to my message, I have throughout the message. I have even sent a message to myself and that's they way it comes through. Below is an example: It's okay! Will read: It s okay . I can't in...

Invalid checksum
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hey all <br><br>I downloaded the trial Home &amp; Student Edition of Office for Mac 2008. The download(s) -- tried redownloading a few times-- went off without a hitch. When I went to install I got the following error: <br><br>The following disk images couldn't be opened: <br> X16-03637_OF2008-122_EN.dmg Invalid checksum <br><br>This was being installed on an administrator account <br> I am running Mac OSx v 10.6.3 <br> Software updates have be...

Print system date on PORcv.xml
I need to print the system date on the report PORcv.xml. Currently this is not possible. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=6cdf05c0-3d13-42fd-82a0-a287b1b51bd...

Newbie struggling with XML in ASP.net evironment
I wrote a class, XMLMgr, that manages the cookies in my cookie.xml file. In my development environment everything works because I had to set the file permission to allow EVERYONE access. This, obviously will not work once I go to a public web server. What do I need to do to put my cookie.xml file on a public web server without giving the folder/file EVERYONE permissions and still allow ASP.net to read and write to it. I have a general understanding of the security processes, starting off with IIS which then hands it off to ASP.net. However, how do I give enough permissions to the secu...

Adding an additional XML node
The below is the article I read today having the same question I want to raise here has no answer yet, so I copy and paste it again with hoping somebody can help out! I have seen samples of custom XML nodes in the eConnect help file eConnect8.0.chm. Has anyone seen code samples that show how to get the node into the struct. If you type 'eConnect business logic, extending' in the index textbox in the chm file you will get a page titled 'Extendign Business Logic'. If you click the link 'XML document' you will be presented with a page containing the following XML. &l...

Limitation of Find and Replace Text in Excel
Location: Posts: 1 Limitation of Find and Replace Text in Excel I am trying to reformat some data in Excel to make some downloade information more easily readable. The information to be manipulated i a. In the download the different items of History are joined togethe with a | delimiter to produce a long wrap around string. I have an Excel macro which finds the | delimiter in the string an converts this to a line break (i.e. vbLF or Alt+Enter). The expecte result is that wherever | occurs, subsequent text is pushed to a ne line. I have found that the macro worked perfectly if the length of...

List of Symbol and Character Number
Is there a way I can get a list of the symbol font and each character num? Niek gave you an answer in the original thread. -- HTH RP (remove nothere from the email address if mailing direct) "Polina" <Polina@discussions.microsoft.com> wrote in message news:D04A8291-2D07-4B74-B96F-FE6F1FFB18B0@microsoft.com... > Is there a way I can get a list of the symbol font and each character num? As I did also. Note: my method is a little easier than Niek's so look at both posts before you decide. Gord Dibben Excel MVP On Wed, 4 May 2005 21:13:46 +0100, "Bob Phill...

What is the fastest/efficient way to replace the root element?
Suppose I have an xml fragment like: <mother> <child name="Bob" sex="M"/> <child name="Jane" sex="F"/> ... </mother> If I wanted to replace the <mother> element to <father> element, what is the fastest or most efficient way to do this? What if I wanted to keep processing instructions, etc. alone that come before the root? Or what if I wanted to drop all non-element(root) stuff out? I am thinking maybe XmlDocument's ReplaceChild? Thanks very much. I realize xsl transform is an option. Let's ...

Group membership query fails because of special character
Hello All. Consider the following script: (watch for word wrap) strComputer = "atl-ws-01" strGroup = "Administrators" Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group") For Each objUser in objGroup.Members Wscript.Echo objUser.Name Next This script works fine; except if there's a dollar sign ($) in the group name. Then I get the dreaded "(null): The group name could not be found." Using "GetObject WinNT", how can I query a (Windows server) local group...

Help with XML/XPATH
Hi, I have the following XML:- <X1> <Props> <Prop xsi:type=\"text\" Name=\"N1\"><Value>TestUser</Value></Prop> <Prop xsi:type=\"bool\" Name=\"flag\"><Value>0</Value></Prop> <Prop xsi:type=\"int\" Name=\"numemp\"><Value>100</Value></Prop> </Props> </X1> I want to extract just the value for a specific <Prop>, for instance I want to be able to just retrieve the Value of the "flag" <Prop>. I am thinking of lo...

Parsing XML over TCP/IP
Sorry if this has been posted before... I am receiving XML messages over a TCP client. Messages vary in size and sometimes can arrive in groups. Thus, I am not guaranteed to receive a full message in a single read from my socket. I am loading each message into an XmlDocument after it arrives. I need a way to make sure I have a complete XML message before I load it into an XmlDocument or it will throw an exception. I am currently finding complete messages by turning each read into a string and manually look for closing tags. Surely there is an easier way to accomplish this, perhaps with ...

Xml fragment in XML document
How do I make this well formed? <?xml version='1.0'?> <xmlvalidationrequest> <xml> <?xml version='1.0'?><test>basic xml fragment<test> </xml> <status>True</status> <errormessage><errormessage> </xmlvalidationrequest> You really have no choice but to strip the <?xml version='1.0'?> directive from the beginning of the XML that you're sending within the <xml> tag. The only alternative I could think of is to wrap the contents of the <xml> tag in a CDATA section, but this...

Replace wildcards with a space
I have a text field with all values containing an asterisk. The asterisk can be located anywhere within the contents. I am trying to replace the asterisk with a space. I will then use TRIM to remove any spaces at the beginning of the text. I have been unable to get an update query to work. When my criteria is like "~[*}", Access says that 0 rows will be updated. When the criteria is [*], I am asked to enter a parameter value. Any assistance will be greatly appreciated. Thanks - bkh Barbara wrote: >I have a text field with all values containing an aste...

Adding static character to a cell
I want to insert a $ in column of cells. Use currency as the format, but I want the $ to stay in the cell so it can be used also when printed out. I hope that's clear? Thanks Frank Frank, The $ in a currency format should also get printed. It is a view of the data, but consistent on screen and print. -- HTH RP (remove nothere from the email address if mailing direct) "Frank" <stratster68@IHATESPAMworldnet.att.net> wrote in message news:%23lA$94VRFHA.3988@tk2msftngp13.phx.gbl... > I want to insert a $ in column of cells. Use currency as the format, but I >...

Export to XML file
Hello, I am using Access 2007 I have a table that I want to export it to XML file. I am able to do this by using export data> xml..... The problem that I have is that in my table, one of the fields can have null value. When I open the exported XML file, I expect to see <field1></field1> if the field1 is null value for that record. But I don't see this at all. How can I force Access to export null value to xml as well? thanks a lot, Boon ...

60% Discount on Convert into XML
Do you need of data format that can use for your content management system? Are you looking for converting your precise data into XML at affordable rates? Need a huge discount on your XML conversion requirements? Then you are at right place. XML Conversion Services help you to store, search and retrieve digital versions of any data. With having 17 years of experience, we provide 99.98% accurate XML conversion solutions worldwide. We can convert your important data from electronic formats to XML such as: =95 Convert HTML to XML =95 Convert PDF to XML =95 Convert Word to XML =95 Convert RTF/T...

Find and Replace #10
We have worksheets that have to be copied forward in the new year. These worksheets refer some worksheets that have not been copied in the new year. So when we do a find and replace from 03 to 04 we have to hit "cancel' sometimes hundreds of times because the files they are referring to have not been copied into the new year yet. Is there some way to suspend the looking for the new referenced file? hi the keyboard keys Cntl+Break will stop the macro if that is what you're wanting. >-----Original Message----- >We have worksheets that have to be copied forward in th...

How do I do a search and replace in a textbox in Excel?
How do I do a search and replace in a textbox in Excel? ...

Character code for Enter Key
Hi, I would like to use the Chr code for the enter key, I know the code for a line break is Chr(11), I've been searching for a table of some kind in help but no luck. Can anyone help me? Thanks http://www.asciitable.com/ Angie M. wrote: >Hi, I would like to use the Chr code for the enter key, I know the code for a >line break is Chr(11), I've been searching for a table of some kind in help >but no luck. Can anyone help me? Thanks -- Gerry Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/word-programming/201003/1 ...

Help with replacing an existing Windows 2003 / Exchange 2003 Serve
I have a computer with Windows 2003 Server, Active Directory, DNS and Exchange 2003 Enterprise edition. I need to replace this computer with a newer more powerful machine. I don't know how to go about doing this. I'm looking for the easist method for accomplishing this task. The only constraint that I have is that I do not wish to change the domain name. I also posted this question on the Windows 2003 migration newsgroup and got the folling response: I recommend that you try these step: 1. Add the new computer to the Windows 2003 domain 2. Run dcpromo to promote it to a DC 3....