Can you form submit XML using a textArea?

Discussion in 'HTML' started by noah, Dec 2, 2006.

  1. noah

    noah Guest

    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
    noah, Dec 2, 2006
    #1
    1. Advertising

  2. 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/
    Benjamin Niemann, Dec 2, 2006
    #2
    1. Advertising

  3. 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.
    Harlan Messinger, Dec 2, 2006
    #3
  4. noah

    noah Guest

    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.
    noah, Dec 2, 2006
    #4
  5. noah

    noah Guest

    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.
    noah, Dec 4, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Dixson
    Replies:
    1
    Views:
    499
    Joe Fallon
    May 18, 2004
  2. Perry van Kuppeveld
    Replies:
    10
    Views:
    6,112
    Grant Merwitz
    Aug 12, 2005
  3. Sjaakie

    Textarea, form submit on return key

    Sjaakie, Jun 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    585
    Sjaakie
    Jun 14, 2006
  4. jatrojoomla
    Replies:
    1
    Views:
    167
  5. Replies:
    3
    Views:
    655
Loading...

Share This Page