473,326 Members | 2,126 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,326 software developers and data experts.

?Best way to escape for xml?

I have an Oracle Procedure that returns xml. There was an exception thrown
when I tried to load an XmlDocument (using LoadXml(String)) because the value
returned from Oracle had an exclamation mark in a text node. So I wrote an
escape method to encode the text coming into the .Net class. But now I am not
sure how to write the unescape method to handle the text when it goes back to
the Oracle db.

Here's what I mean:
- if the data in the db is "abc ! & ' " < > efg", the procedure produces
this element

<data>abc &#x21; & " ' < > xyz</data>

- loading this into an XmlDocument using thedocument.LoadXml(oraclestring)
leaves

<data>abc ! & ' " < > xyz</data>

So do I write a method to change the "&", "<" and ">" back to "&<>" in
Oracle? How many other characters are changed and to what? Why was it bad for
me to give an "!" in the string when .Net then uses it unescaped thereafter?
I await enlightenment peacefully.

Nov 12 '05 #1
3 5348
Doh! I forgot to escape the message I sent. The middle part should look like
this

Here's what I mean:
- if the data in the db is "abc ! & ' " < > efg", the procedure produces
this element<br>
&lt;data>abc &#x21; &#x26; &#x27; &#x22; &#x3C; &#x3D; xyz</data>
<br>
- loading this into an XmlDocument using thedocument.LoadXml(oraclestring)
leaves
<br>
<data>abc ! &amp; ' " &lt; &gt; xyz</data>
<br>
So do I write a method to change the "&amp;", "&lt;" and "&gt;" back to
"&<>" in
Oracle?

"beanweed" wrote:
I have an Oracle Procedure that returns xml. There was an exception thrown
when I tried to load an XmlDocument (using LoadXml(String)) because the value
returned from Oracle had an exclamation mark in a text node. So I wrote an
escape method to encode the text coming into the .Net class. But now I am not
sure how to write the unescape method to handle the text when it goes back to
the Oracle db.

Here's what I mean:
- if the data in the db is "abc ! & ' " < > efg", the procedure produces
this element

<data>abc ! & " ' < > xyz</data>

- loading this into an XmlDocument using thedocument.LoadXml(oraclestring)
leaves

<data>abc ! & ' " < > xyz</data>

So do I write a method to change the "&", "<" and ">" back to "&<>" in
Oracle? How many other characters are changed and to what? Why was it bad for
me to give an "!" in the string when .Net then uses it unescaped thereafter?
I await enlightenment peacefully.

Nov 12 '05 #2
Hi,

You might want to take a look at http://www.w3.org/TR/REC-xml/#syntax
first. It is unlikely that the problem is caused by the '!'; '&' is the
culprit.
Whatever you're getting is not well-formed xml. You'll need to change the
source so that it applies the following character mapping on serialization:
for character data:
< -> &lt;
& -> &amp;
for attribute values the above plus:
' -> &apos;
" -> &quot;
Unless you have a very specialized scenario you cannot consistently filter
the
input unless you're parsing the xml at the same time. You probably don't
want
to do that. Another alternative is to use CDATA sections for the text.
Again,
that's reasonable provided that you have control of the source
serialization.

Ion

"beanweed" <be******@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
I have an Oracle Procedure that returns xml. There was an exception thrown
when I tried to load an XmlDocument (using LoadXml(String)) because the value returned from Oracle had an exclamation mark in a text node. So I wrote an
escape method to encode the text coming into the .Net class. But now I am not sure how to write the unescape method to handle the text when it goes back to the Oracle db.

Here's what I mean:
- if the data in the db is "abc ! & ' " < > efg", the procedure produces
this element

<data>abc &#x21; & " ' < > xyz</data>

- loading this into an XmlDocument using thedocument.LoadXml(oraclestring)
leaves

<data>abc ! & ' " < > xyz</data>

So do I write a method to change the "&", "<" and ">" back to "&<>" in
Oracle? How many other characters are changed and to what? Why was it bad for me to give an "!" in the string when .Net then uses it unescaped thereafter? I await enlightenment peacefully.

Nov 12 '05 #3
Thanks for your help. Subsequent investigation leads me to believe that,
although the original error was and is reported to have been caused by the
line containing "xmldoc.LoadXml(oraclestring)", it was the next line
containing "xmlcontrol.Document = xmldoc" and the tranformation of the xml
using an xsl document that is the fault. (Removing this line stops the
problem, changing the xsl solves it.) I will change my encode and decode
methods (in Java on the Oracle server) to comply with your suggestion and the
W3 specification. But I will remain puzzled as to why .Net just ignored
"&#x21;"(?).

"Ion Vasilian" wrote:
Hi,

You might want to take a look at http://www.w3.org/TR/REC-xml/#syntax
first. It is unlikely that the problem is caused by the '!'; '&' is the
culprit.
Whatever you're getting is not well-formed xml. You'll need to change the
source so that it applies the following character mapping on serialization:
for character data:
< -> <
& -> &
for attribute values the above plus:
' -> &apos;
" -> "
Unless you have a very specialized scenario you cannot consistently filter
the
input unless you're parsing the xml at the same time. You probably don't
want
to do that. Another alternative is to use CDATA sections for the text.
Again,
that's reasonable provided that you have control of the source
serialization.

Ion

"beanweed" <be******@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
I have an Oracle Procedure that returns xml. There was an exception thrown
when I tried to load an XmlDocument (using LoadXml(String)) because the

value
returned from Oracle had an exclamation mark in a text node. So I wrote an
escape method to encode the text coming into the .Net class. But now I am

not
sure how to write the unescape method to handle the text when it goes back

to
the Oracle db.

Here's what I mean:
- if the data in the db is "abc ! & ' " < > efg", the procedure produces
this element

<data>abc ! & " ' < > xyz</data>

- loading this into an XmlDocument using thedocument.LoadXml(oraclestring)
leaves

<data>abc ! & ' " < > xyz</data>

So do I write a method to change the "&", "<" and ">" back to "&<>" in
Oracle? How many other characters are changed and to what? Why was it bad

for
me to give an "!" in the string when .Net then uses it unescaped

thereafter?
I await enlightenment peacefully.


Nov 12 '05 #4

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

Similar topics

11
by: Dave Smithz | last post by:
Having adopted someone else's PHP cope and completing a crash course in the language I came across a (probably common) problem with the current code. On a registration form, whenever users names...
8
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
7
by: Leif B. Kristensen | last post by:
I'm working with a Python program to insert / update textual data into a PostgreSQL database. The text has single and double quotes in it, and I wonder: What is the easiest way to escape quotes in...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
3
by: Guadala Harry | last post by:
I'd like to know the answer to the following question so I can know what to expect with regard to other similar uses of escape characters and strings. While everything works fine - I'd like to know...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.