views:

43

answers:

1

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.

+1  A: 

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.

Andreas_D
Thanks, great. Now i have string like: /?we=<network ip_addr="10.0.0.0/8" save_ip="true"><subnet interf_used="200" name="lan1" /><subnet interf_used="254" name="lan2" /></network>How can i put it to for example an array?
MichalBE