473,378 Members | 1,617 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,378 software developers and data experts.

Incomplete Escaping Functionality??

Hello All...

I am in an app that needs to write out an XML document for transmittal to an
outside organization. All good and fine... I create the XmlDocument object,
append all my nodes, and values etc etc... and it all works.

Now I go to save the file... I tried two methods...
MyXmlDocument.Save(filename) and
My.Computer.FileSystem.WriteAllText(filename, MyXmlDoc.OuterXml, False)

The problem comes in with XmlDocument.OuterXml. According to XML, there are
5 characters which need to be escaped... Ampersand, LessThan, GreaterThan,
Apostrophe and DoubleQuote. XmlDocument.OuterXml, escapes only three of
these ( & , < and ). Apostrophe and DoubleQuote do not get escaped. This
is a problem, because the third party we need to deal with *must* have them
escaped, even inside of a Nodes InnerText.
So I figured okay, I'll just escape them myself, but when I try to do that,
it winds up escaping my Ampersand (for example in "&quot;" ), so that it
winds up saving "&amp;quot;".

How in the world can I tell it that it needs to escape ALL FIVE CHARACTERS?
Thanks in advance,
- Arthur Dent.

Oct 18 '06 #1
3 1727
"Arthur Dent" <hi*********************@yahoo.comwrote in message
news:F5**********************************@microsof t.com...
Hello All...

I am in an app that needs to write out an XML document for transmittal to
an outside organization. All good and fine... I create the XmlDocument
object, append all my nodes, and values etc etc... and it all works.

Now I go to save the file... I tried two methods...
MyXmlDocument.Save(filename) and
My.Computer.FileSystem.WriteAllText(filename, MyXmlDoc.OuterXml, False)

The problem comes in with XmlDocument.OuterXml. According to XML, there
are 5 characters which need to be escaped... Ampersand, LessThan,
GreaterThan, Apostrophe and DoubleQuote. XmlDocument.OuterXml, escapes
only three of these ( & , < and ). Apostrophe and DoubleQuote do not get
escaped. This is a problem, because the third party we need to deal with
*must* have them escaped, even inside of a Nodes InnerText.
So I figured okay, I'll just escape them myself, but when I try to do
that, it winds up escaping my Ampersand (for example in "&quot;" ), so
that it winds up saving "&amp;quot;".

Exactly what are you trying to escape? Do you have these characters within
text nodes? If so, you need to escape them when you create the text node.

John
Oct 18 '06 #2
Arthur Dent wrote:
I am in an app that needs to write out an XML document for transmittal
to an outside organization. All good and fine... I create the
XmlDocument object, append all my nodes, and values etc etc... and it
all works.

Now I go to save the file... I tried two methods...
MyXmlDocument.Save(filename) and
My.Computer.FileSystem.WriteAllText(filename, MyXmlDoc.OuterXml, False)

The problem comes in with XmlDocument.OuterXml. According to XML, there
are 5 characters which need to be escaped... Ampersand, LessThan,
GreaterThan, Apostrophe and DoubleQuote. XmlDocument.OuterXml, escapes
only three of these ( & , < and ). Apostrophe and DoubleQuote do not
get escaped. This is a problem, because the third party we need to deal
with *must* have them escaped, even inside of a Nodes InnerText.
XML spec says this:

"The ampersand character (&) and the left angle bracket (<) MUST NOT
appear in their literal form, except when used as markup delimiters, or
within a comment, a processing instruction, or a CDATA section. If they
are needed elsewhere, they MUST be escaped using either numeric
character references or the strings "&amp;" and "&lt;" respectively. The
right angle bracket (>) may be represented using the string "&gt;", and
MUST, for compatibility, be escaped using either "&gt;" or a character
reference when it appears in the string "]]>" in content, when that
string is not marking the end of a CDATA section.

To allow attribute values to contain both single and double quotes, the
apostrophe or single-quote character (') may be represented as "&apos;",
and the double-quote character (") as "&quot;"."

So & and < MUST always be escaped, while >, ' and " only must be escaped
under certain circumstances, otherwise they MAY be escaped.

But actually you shouldn't care about XML syntax, XML takes care of it.
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Oct 19 '06 #3
I have an XmlNode whose InnerText property contains DoubleQuote.
This causes problem with the 3rd party, because their software cannot handle
the doublequote in the innertext.
When I tried to manually escape it using "&quot;", the Xml parser escaped my
"&" on me, and saved it to the file as "&amp;quot;"... effectively making it
impossible for me to manually escape the doublequote.

Ultimately, I wound up adding the text inside of a CDATA section. This
worked for the 3rd party.
From looking around though, it looked online, like CDATA is a holdover, and
not the recommended way of doing things.


"Oleg Tkachenko [MVP]" <so**@body.comwrote in message
news:45**************@body.com...
Arthur Dent wrote:
>I am in an app that needs to write out an XML document for transmittal to
an outside organization. All good and fine... I create the XmlDocument
object, append all my nodes, and values etc etc... and it all works.

Now I go to save the file... I tried two methods...
MyXmlDocument.Save(filename) and
My.Computer.FileSystem.WriteAllText(filename, MyXmlDoc.OuterXml, False)

The problem comes in with XmlDocument.OuterXml. According to XML, there
are 5 characters which need to be escaped... Ampersand, LessThan,
GreaterThan, Apostrophe and DoubleQuote. XmlDocument.OuterXml, escapes
only three of these ( & , < and ). Apostrophe and DoubleQuote do not
get escaped. This is a problem, because the third party we need to deal
with *must* have them escaped, even inside of a Nodes InnerText.

XML spec says this:

"The ampersand character (&) and the left angle bracket (<) MUST NOT
appear in their literal form, except when used as markup delimiters, or
within a comment, a processing instruction, or a CDATA section. If they
are needed elsewhere, they MUST be escaped using either numeric character
references or the strings "&amp;" and "&lt;" respectively. The right angle
bracket (>) may be represented using the string "&gt;", and MUST, for
compatibility, be escaped using either "&gt;" or a character reference
when it appears in the string "]]>" in content, when that string is not
marking the end of a CDATA section.

To allow attribute values to contain both single and double quotes, the
apostrophe or single-quote character (') may be represented as "&apos;",
and the double-quote character (") as "&quot;"."

So & and < MUST always be escaped, while >, ' and " only must be escaped
under certain circumstances, otherwise they MAY be escaped.

But actually you shouldn't care about XML syntax, XML takes care of it.
--
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
Oct 19 '06 #4

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

Similar topics

4
by: Dave Moore | last post by:
Hi All, Can anybody point me to a FAQ or similar that describes what all this stuff is about please?. I'm interfacing with a MySQL database if that's relavent. I've read a couple of books which...
1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
5
by: bobbyballgame | last post by:
I am having a problem calling Stored Procedures: .... dim MyValue, MyOtherValue MyValue = "Bobby's value" MyOtherValue = Bobby's other value" rs.Open "exec MyStoredProc """ & MyValue &...
5
by: Paul F. Dietz | last post by:
Is the following legal C? struct foo; struct foo (*p); /* Pointer to array of 10 foo structures */ struct foo { int bar; int baz; }; main() { printf("%d\n", sizeof(*p)); } Paul Dietz...
4
by: Mitchell Vincent | last post by:
Is there some built in functionality to escape special characters for use through ADO? I'm sure I could manually replace the ' with ' (if that is the right escape sequence), but I'm afriad I just...
11
by: Geoff Caplan | last post by:
Hi folks, The thread on injection attacks was very instructive, but seemed to run out of steam at an interesting point. Now you guys have kindly educated me about the real nature of the issues,...
3
by: Arthur Dent | last post by:
Hello All... I am in an app that needs to write out an XML document for transmittal to an outside organization. All good and fine... I create the XmlDocument object, append all my nodes, and...
3
by: Taras_96 | last post by:
Hi everyone, I'm having a bit of trouble understanding the purpose of escaping nulls, and the use of addcslashes. Firstly, the manual states that: "Strictly speaking, MySQL requires only...
1
by: David Henderson | last post by:
I know 'disable-output-escaping' has been discussed in the past, but I can't put my finger on any of the threads to see if my current problem is addressed. Sorry for re-asking the question if it...
23
by: Fred | last post by:
if I use mysql_real_escape_string on all INSERT or UPDATE queries, then would a stored procedure provide any extra protection? the user has to be granted UPDATE and/or INSERT privileges anyway. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.