qqryq
qqryq

Reputation: 1924

how to use XML sent by html form?

i have html form with textarea in which i paste some XML, for example:

<network ip_addr="10.0.0.0/8" save_ip="true">
<subnet interf_used="200" name="lan1" />
<subnet interf_used="254" name="lan2" />
</network>

When user submit form, that data is send to Java server, so in headers i get something like that:

GET /?we=%3Cnetwork+ip_addr%3D%2210.0.0.0%2F8%22+save_ip%3D%22true%22%3E%0D%0A%3Csubnet+interf_used%3D%22200%22+name%3D%22lan1%22+%2F%3E%0D%0A%3Csubnet+interf_used%3D%22254%22+name%3D%22lan2%22+%2F%3E%0D%0A%3C%2Fnetwork%3E HTTP/1.1

how can i use that in my Java applications? I need to make some calculations on that data and re-send new generated XML.

Upvotes: 0

Views: 86

Answers (1)

Andreas Dolk
Andreas Dolk

Reputation: 114817

This answer shows how to use the URLDecoder/URLEncoder classes to decode and encode url strings. It should work if you passed the 'GET' string to the URLDecoders decode method.


To answer your following question (comment)

First you need to extract this xml based response from the url string. Maybe it's enough to create a substring starting with the first < char.

The String should be fed into a XML parser to create a DOM document. The last easy task would be walking through that document and copying the values to your internal network model.

Do not think about using RegExp to extract the data. Use a parser.

Upvotes: 1

Related Questions