Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 7th, 2007, 04:55 PM
Jo M
Guest
 
Posts: n/a
Default Regular Expressions to XML

Hello,

Does anyone of you know any tool that would convert regular expressions
to XML compatible form?

I mean tool that would convert e.g. & to & etc.

I have written an ASP.NET C# application that uses regular expressions
stored in XML file but a tool that would convert Regexp to XML compatible
form would be nice,

Cheers!



  #2  
Old March 7th, 2007, 05:35 PM
Keith Patrick
Guest
 
Posts: n/a
Default Re: Regular Expressions to XML

It's not a tool, per se, but the framework has built-in escaping:
System.Text.StringBuilder sb = new System.Text.StringBuilder();

new System.Xml.XmlTextWriter(new
System.IO.StringWriter(sb)).WriteString("&");






  #3  
Old March 7th, 2007, 05:35 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Regular Expressions to XML

Jo M wrote:
Quote:
Does anyone of you know any tool that would convert regular expressions
to XML compatible form?
>
I mean tool that would convert e.g. & to & etc.
>
I have written an ASP.NET C# application that uses regular expressions
stored in XML file but a tool that would convert Regexp to XML compatible
form would be nice,
You can use XmlWriter and its WriteString method to escape a string e.g.

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.ConformanceLevel = ConformanceLevel.Fragment;
using (XmlWriter xmlWriter = XmlWriter.Create(Console.Out,
writerSettings)) {
xmlWriter.WriteString("Kibo & Xibo");
}

outputs "Kibo & Xibo".


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  #4  
Old March 7th, 2007, 06:35 PM
Jo M
Guest
 
Posts: n/a
Default Thanks! Re: Regular Expressions to XML

Thanks for sharing your info.

Cheers!

"Jo M" <jom121@hotmail.comwrote in message
news:esmprg$c6f$1@nyytiset.pp.htv.fi...
Quote:
Hello,
>
Does anyone of you know any tool that would convert regular expressions
to XML compatible form?
>
I mean tool that would convert e.g. & to &amp; etc.
>
I have written an ASP.NET C# application that uses regular expressions
stored in XML file but a tool that would convert Regexp to XML compatible
form would be nice,
>
Cheers!
>
>
>

  #5  
Old March 7th, 2007, 07:05 PM
Jo M
Guest
 
Posts: n/a
Default Still one question Re: Regular Expressions to XML

Hello again!

I wrote a small Windows App that converts
characters to XML.

Code below:
StringBuilder sb = new StringBuilder();

new System.Xml.XmlTextWriter(new

StringWriter(sb)).WriteString(this.txtBoxFrom.Text );

this.txtBoxTo.Text = sb.ToString();

If I give & to txtBoxFrom field it writes &amp; to txtBoxTo field

but when givin " it writes " not &quot; that it should write.

Can anyone point what is still missing?

Cheers!

"Jo M" <jom121@hotmail.comwrote in message
news:esmprg$c6f$1@nyytiset.pp.htv.fi...
Quote:
Hello,
>
Does anyone of you know any tool that would convert regular expressions
to XML compatible form?
>
I mean tool that would convert e.g. & to &amp; etc.
>
I have written an ASP.NET C# application that uses regular expressions
stored in XML file but a tool that would convert Regexp to XML compatible
form would be nice,
>
Cheers!
>
>
>

  #6  
Old March 7th, 2007, 08:15 PM
Keith Patrick
Guest
 
Posts: n/a
Default Re: Still one question Re: Regular Expressions to XML

Hmm, that's a weird one. I had to go in and read some docs on it a bit, but
the problem is that the quote is only escaped when in the context of an
attribute:
WriteString does the following

a.. The characters &, <, and are replaced with &amp;, &lt;, and &gt;,
respectively.

b.. Character values in the range 0x-0x1F (excluding white space
characters 0x9, 0xA, and 0xD) are replaced with numeric character entities
(� through &#0x1F).

c.. If WriteString is called in the context of an attribute value, double
and single quotes are replaced with &quot; and &apos; respectively.



You'd need to do a WriteAttribute to get the write in context of an
attribute to tell the writer that it is writing between two existing
quotation marks and hence needs escaping.



 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles