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

Home Posts Topics Members FAQ

How to stop Symbols being converted

Hello,
I have a console app that converts fields from a database into xml
files and am having problems with 'Greater Than' and 'Less Than'
symbols being converted into their html equivalents (</ >)
automatically. I need them to stay as < so that HTML controls render
correctly when the XML file is XSLT transformed in the consuming web
app.

At the moment, I am building the XML file like this:

MemoryStream msQuestion = new MemoryStream();
StreamReader myReader = new StreamReader(msQuestion);
XmlTextWriter xtwQuestion = new XmlTextWriter(msQuestion,
Encoding.UTF8);
string strQuestion = "";
DataRow myBody = dsQA.Tables[0].Rows[0];
DataRow myRow;

xtwQuestion.WriteStartDocument();
xtwQuestion.WriteStartElement("questions");
xtwQuestion.WriteElementString("question",
myBody["question"].ToString());
....
xtwQuestion.WriteEndElement();//question
xtwQuestion.WriteEndDocument();
xtwQuestion.Flush();

msQuestion.Position = 0;
strQuestion = myReader.ReadToEnd();
msQuestion.Flush();

The problem is that when inspected, the string 'strQuestion' contains
&lt;/ &gt; instead of < >

I've checked and the database value contains < >, so the conversion
must be done automatically somewhere.

Is there anyway to stop this conversion and leave the symbols as they
are?

Thanks for your time,
J

Nov 24 '06 #1
4 4033
actually, ignore this, i've just answered my own question - it's
because < are invalid xml chars...
jumblesale wrote:
Hello,
I have a console app that converts fields from a database into xml
files and am having problems with 'Greater Than' and 'Less Than'
symbols being converted into their html equivalents (&lt;/ &gt;)
automatically. I need them to stay as < so that HTML controls render
correctly when the XML file is XSLT transformed in the consuming web
app.

At the moment, I am building the XML file like this:

MemoryStream msQuestion = new MemoryStream();
StreamReader myReader = new StreamReader(msQuestion);
XmlTextWriter xtwQuestion = new XmlTextWriter(msQuestion,
Encoding.UTF8);
string strQuestion = "";
DataRow myBody = dsQA.Tables[0].Rows[0];
DataRow myRow;

xtwQuestion.WriteStartDocument();
xtwQuestion.WriteStartElement("questions");
xtwQuestion.WriteElementString("question",
myBody["question"].ToString());
...
xtwQuestion.WriteEndElement();//question
xtwQuestion.WriteEndDocument();
xtwQuestion.Flush();

msQuestion.Position = 0;
strQuestion = myReader.ReadToEnd();
msQuestion.Flush();

The problem is that when inspected, the string 'strQuestion' contains
&lt;/ &gt; instead of < >

I've checked and the database value contains < >, so the conversion
must be done automatically somewhere.

Is there anyway to stop this conversion and leave the symbols as they
are?

Thanks for your time,
J
Nov 24 '06 #2
Well, you don't make it clear what the context is; if a typical question is
"is 5 < 4", then this is the *correct* handling, and &lt; will render
correctly as < in the browser; if a typical question is itself HTML / XML,
then you could append the literal (WriteRaw()), but be aware that this does
risk injection attacks if someboody can get <SCRIPT/or <OBJECT/or
<IFRAME/etc tags into the questions.

So what is a typcial question?

Marc
Nov 24 '06 #3
Hello,

Does your database not support select as XML? Also, a DataSet will
provide you with xml.

--
Cheers,
Gary
http://www.garyshort.org/

jumblesale wrote:
Hello,
I have a console app that converts fields from a database into xml
files and am having problems with 'Greater Than' and 'Less Than'
symbols being converted into their html equivalents (&lt;/ &gt;)
automatically. I need them to stay as < so that HTML controls render
correctly when the XML file is XSLT transformed in the consuming web
app.

At the moment, I am building the XML file like this:

MemoryStream msQuestion = new MemoryStream();
StreamReader myReader = new StreamReader(msQuestion);
XmlTextWriter xtwQuestion = new XmlTextWriter(msQuestion,
Encoding.UTF8);
string strQuestion = "";
DataRow myBody = dsQA.Tables[0].Rows[0];
DataRow myRow;

xtwQuestion.WriteStartDocument();
xtwQuestion.WriteStartElement("questions");
xtwQuestion.WriteElementString("question",
myBody["question"].ToString());
...
xtwQuestion.WriteEndElement();//question
xtwQuestion.WriteEndDocument();
xtwQuestion.Flush();

msQuestion.Position = 0;
strQuestion = myReader.ReadToEnd();
msQuestion.Flush();

The problem is that when inspected, the string 'strQuestion' contains
&lt;/ &gt; instead of < >

I've checked and the database value contains < >, so the conversion
must be done automatically somewhere.

Is there anyway to stop this conversion and leave the symbols as they
are?

Thanks for your time,
J
Nov 24 '06 #4
No - < and are definitely valid xml characters, but they need to be
escaped if you mean "a string with a less-than sign".

Note that CDATA can also be of use in wrapping malformed strings, but in
your case I think it is already doing the right thing. XSLT and browsers
will both know what the &lt; means.

Marc
Nov 24 '06 #5

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

Similar topics

4
by: gabor | last post by:
hi, today i made some tests... i tested some unicode symbols, that are above the 16bit limit (gothic:http://www.unicode.org/charts/PDF/U10330.pdf) .. i played around with iconv and so on,...
7
by: Torbak | last post by:
I got some question about symbols in libraries ... In libraries, there is public symbols and "not public" symbols (private, static)... In C when we use the "static" keyword on the declaration of...
1
by: aerobar2 | last post by:
When I debug my application I get "no symbols loaded" ================= 'DefaultDomain': Loaded 'c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded. 'MHSFire': Loaded...
1
by: asdf | last post by:
Hello, I was enjoying working in VS for half a year without any problems and now I cannot debug anymore. Without any really reason my Studio tells me that the page that I want to debug has - No...
2
by: lafleur | last post by:
I solved this problem, and thought I should post a solution for it. I converted a VB.NET web app to C# using SharpDevelop. When I went to run the C# version, the IDE was ignoring breakpoints -...
10
by: RDI | last post by:
What's it mean? My prog runs fine. Then as soon as I press ok or cancel, the following is what's in the output area of the debugger. TIA -- RDI (remove the exclamation from the email...
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
7
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
3
by: JV | last post by:
Hi All, I am new to C# and I am having trouble compiling and running code. I have the code written (it was just an example that I took) and I run it, it gives me No Symbols loaded error as...
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...
1
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...
1
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...
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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.