Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Can you form submit XML using a textArea?

Reply
Thread Tools

Can you form submit XML using a textArea?

 
 
noah
Guest
Posts: n/a
 
      12-02-2006
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

 
Reply With Quote
 
 
 
 
Benjamin Niemann
Guest
Posts: n/a
 
      12-02-2006
Hello,

noah wrote:

> 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

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
 
Reply With Quote
 
 
 
 
Harlan Messinger
Guest
Posts: n/a
 
      12-02-2006
noah wrote:
> 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.
 
Reply With Quote
 
noah
Guest
Posts: n/a
 
      12-02-2006
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





Harlan Messinger wrote:
> noah wrote:
> > 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.


 
Reply With Quote
 
noah
Guest
Posts: n/a
 
      12-04-2006
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

noah wrote:
> 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
>
>
>
>
>
> Harlan Messinger wrote:
> > noah wrote:
> > > 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.


 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert form to submit on load instead of clicking submit button? Network-Man HTML 5 07-07-2012 12:06 PM
submit 1 form to 2 servers or 2 forms to 2 server (1 form each) on 1 submit abansal.itp@gmail.com Javascript 3 06-23-2007 07:29 AM
How to submit a from using JavaScript [without using submit button]? jatrojoomla Javascript 1 08-24-2006 04:46 AM
Forms with multiple submit buttons vs 'form' objects with single 'submit' methods neil.fitzgerald@ic.ac.uk Python 4 04-14-2006 04:58 PM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM



Advertisments