encode send and recieve xml data across asp.net pages

V

vicky

hello guys, there are some values in a asp.net page and i have to xml
encode them (convert them into some xml format ) and send them to some
other page(via querystring) and decode there to use those values. If
anybody can guide how to do it will be good. :)
 
B

Brian Cryer

vicky said:
hello guys, there are some values in a asp.net page and i have to xml
encode them (convert them into some xml format ) and send them to some
other page(via querystring) and decode there to use those values. If
anybody can guide how to do it will be good. :)

If you need to pass values from one page to another via the query string,
then you don't need to xml encode them.

If you are using the query string then you can only pass string values from
one page to another, but that isn't normally a problem because its easy
enough to convert numeric values to and from a string. If however you need
to pass something more complex (i.e. an object) then you could serialise the
object and then pass it as a string, but if your objects are large then
passing them via the query string isn't optimum.

To build up your query string is quite straight forward. Lets say you have
two variables "A" and "B" then your query string would look something like:

example.com?A=1&B=2

so ? after the URL and & between subsequent variables.

At the other end you would get the value using (VB.Net - but the C# syntax
won't be too different):

int a = HttpContext.Current.Request.QueryString.Item("A")
int b = HttpContext.Current.Request.QueryString.Item("B")

When passing string values use HttpUtility.HtmlEncode to encode the string
(because spaces, ampersands and some other characters have special meanings)
and HttpUtility.HtmlDecode to decode the value at the destination page to
get back to the original string.

I hope that's sufficient to get you going.
 
V

vicky

If you need to pass values from one page to another via the query string,
then you don't need to xml encode them.

If you are using the query string then you can only pass string values from
one page to another, but that isn't normally a problem because its easy
enough to convert numeric values to and from a string. If however you need
to pass something more complex (i.e. an object) then you could serialise the
object and then pass it as a string, but if your objects are large then
passing them via the query string isn't optimum.

To build up your query string is quite straight forward. Lets say you have
two variables "A" and "B" then your query string would look something like:

    example.com?A=1&B=2

so ? after the URL and & between subsequent variables.

At the other end you would get the value using (VB.Net - but the C# syntax
won't be too different):

  int a = HttpContext.Current.Request.QueryString.Item("A")
  int b = HttpContext.Current.Request.QueryString.Item("B")

When passing string values use HttpUtility.HtmlEncode to encode the string
(because spaces, ampersands and some other characters have special meanings)
and HttpUtility.HtmlDecode to decode the value at the destination page to
get back to the original string.

I hope that's sufficient to get you going.

The problem with me is that i have to do like i mentioned before. i
have never worked with xml , i have solid grasp of asp.net
concept(that you tried to explain-anyway thanx for that), my question
is actuallly more towards encoding and decoding some data as xml in
dotnet using csharp.
 
B

Brian Cryer

The problem with me is that i have to do like i mentioned before. i
have never worked with xml , i have solid grasp of asp.net
concept(that you tried to explain-anyway thanx for that), my question
is actuallly more towards encoding and decoding some data as xml in
dotnet using csharp.

1. Do you need to work with XML? If you are simply passing data from one
page to another then you don't need XML.

2. If you need to convert an object to XML then I suggest you look at the
XmlSerializer class. The online help gives a simple example of how to convet
an object to XML - although if you have a specific XML schema in mind then
you may be better off generating the XML yourself.

Hope this helps.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top