Forum Moderators: open

Message Too Old, No Replies

Embed XML in form variable

         

zeon

10:43 pm on Feb 9, 2008 (gmt 0)

10+ Year Member



Is this possible to include a XML string in the HTML form variable?

Here is the actual XML string:

<corp>
<report permission="10">
<abstract permission="4"/>
<transfer permission="10"/>
<summary permission="5"/>
<billing permission="10"/>
<annuity permission="0"/>
</report>
</corp>

For example if I want to include the xml like this, is it going to work?

<form action="myServlet" method="post">

<input type="hidden" name="xmlFile" value="<corp><report permission="10"><abstract permission="4"/><transfer permission="10"/><summary permission="5"/><billing permission="10"/><annuity permission="0"/></report>
</corp>">

<input type="submit" value="Send">
</form>

-zeon

cmarshall

11:01 pm on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

I don't think it should be a problem, as long as you use HTML entities ("&lt;" instead of "<", etc.)

zeon

11:31 pm on Feb 9, 2008 (gmt 0)

10+ Year Member



Greetings,

Thanks for the tips! So with the HTML encoding, it shouldn't be a problem in processing the string in the Servlet backend with request.getParameter().

String xmlData = request.getParameter("xmlFile");

That's nice to know!

-zeon

cmarshall

12:34 am on Feb 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're reading it like that, then what the server sends up can be "real" XML (not escaped). If you will be including it on an HTML page (like in a <form> element value attribute), then it may need to be escaped. I think that JS-applied values can be unescaped (not sure).

So::

 String xmlData = request.getParameter("xmlFile");
// This may not need to be escaped.
document.getElementById('some_form_element').value=String;
// However, this may.
document.getElementById('some_div_element').innerHTML='<input type="text" value="'+String+'" />';

zeon

6:56 am on Feb 10, 2008 (gmt 0)

10+ Year Member



Ok. We'll try the following encoding works as intended.

<input type="hidden" name="xmlFile" value="&lt;corp>&lt;report permission=&quot;10&quot;&gt;&lt;abstract permission=&quot;4&quot;/&gt;&lt;transfer permission=&quot;10&quot;/&gt;&lt;summary permission=&quot;5&quot;/&gt;&lt;billing permission=&quot;10&quot;/&gt;&lt;annuity permission=&quot;0&quot;/&gt;&lt;/report&gt;
&lt;/corp&gt;">

Thanks,
zeon

zeon

10:53 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



Indeed the encoding works as intended.

Thanks!

-zeon

cmarshall

12:05 am on Feb 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad it worked out.