Can you form submit XML using a textArea?

N

noah

My user needs to cut and paste XML and submit it using a simple HTML
form.

I have created a textarea:

<textarea rows="10" cols="60" name="xml">
</textarea>

The problem is the special characters in the XML mess up the submit. I
need everything pasted to this textarea to be treated like CDATA (I
think), or somehow full escaped.

Is this possible?

Thanks in advance,
James
 
B

Benjamin Niemann

Hello,
My user needs to cut and paste XML and submit it using a simple HTML
form.

I have created a textarea:

<textarea rows="10" cols="60" name="xml">
</textarea>

The problem is the special characters in the XML mess up the submit. I
need everything pasted to this textarea to be treated like CDATA (I
think), or somehow full escaped.

Is this possible?

Whatever the user types or pastes into the textarea is submitted unchanged
to the server (except for some encoding issues).
The 'messing up' probably happends later down in the processing pipeline.

What are you doing with the submitted data?

Do you want to (re-)display the textarea, prefilled with the previously
submitted data? In this case you have to escape all '<' and '&' in the data
between the textarea start and end tags.
Same thing, if you want to display the XML literally in a HTML document.

HTH
 
H

Harlan Messinger

noah said:
My user needs to cut and paste XML and submit it using a simple HTML
form.

I have created a textarea:

<textarea rows="10" cols="60" name="xml">
</textarea>

The problem is the special characters in the XML mess up the submit. I
need everything pasted to this textarea to be treated like CDATA (I
think), or somehow full escaped.

Can you be more clear than "mess up the submit"? What is the actual
error that's occurring? Characters like <, >, ', ", etc. work just fine
in forms. The most likely problem that comes to mind is that you're
trying to put the data into a database by building a query string in
your application like

sql = "insert into T (xml) values ('" + xmlInput + "')";

and the input data has apostrophes (single quotes) in it that need to be
escaped to keep the SQL engine from treating them as delimiters in the
query.
 
N

noah

Hi,

Thanks for the quick responses. I should have been more clear about the
submit.

I have simple java servlet (a Sping FrameworkServlet) running on a
tomcat app server. It does some basic processing of the HttpRequest.

The behavior I am seeing is, I can type a basic string in the textarea,
e.g. "Helllo", and click submit. Debugging the servlet on the server I
can see the request come in fine, with the 'Hello' string set as the
value on my parameter named 'xml'.

However, if I then repeat the test but place XML formed data, e.g. :
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Jim</to>
<from>Bob</from>
<body>Don't forget this weekend!</body>
</note>

The form does not seem to submit. I do not catch the HttpRequest on the
server.

If an HTML textarea does indeed submit precisely what is pasted, then
my problem may lay elsewhere. My first hunch though was that the
problem was on the browser/html side.

Thx,
Noah
 
N

noah

For reference. It was in fact the XML syntax screwing this up. A
solution which worked for me.

Write a small javascript function to wrap the entire contents of the
text area in a CDATA tag and then submit the form. EG:

function doSubmit() {
var xml = document.getElementByName("xml").value;
xml = "<![CDATA[" + xml + "]]>";
document.getElementByName("xml").value = xml;
document.getElementById("form").submit();
}

Then, simply override the submit buttons onclick to call the javascript
function.

<input type="submit" onclick="javascript:doSubmit(); return true;">

A CDATA tag tells most parsers to totally ignore anything inbetween. So
all the special chars in the XML are are ignored, and don't mess up the
transmission.

noah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top