Datasheet

Chapter 1: AJAX Technologies
18
Listing 1-3 (continued)
{
// Same as Listing 2
}
function serialize(credentials)
{
// Same as Listing 2
}
function submitCallback()
{
// Same as Listing 2
}
</script>
</head>
<body>
<form id=”form1” runat=”server”>
<!- Same as Listing 2 ->
</form>
</body>
</html>
Now let’s walk through the implementations of the Page_Load server-side method and the
deserialize JavaScript function in this listing, starting with the Page_Load method.
The
Page_Load method begins by instantiating a StringWriter into which the XML data will be
written:
string xml = ””;
using (StringWriter sw = new StringWriter())
Then it instantiates an XmlWriterSettings object that specifies the settings for the XML document. In
this case, the XML document will be indented and it will not contain the XML declaration:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
Next, it instantiates an XmlWriter object with the specified settings and wraps the StringWriter . In
other words, this
XmlWriter will write the XML into the StringWriter :
using (XmlWriter xw = XmlWriter.Create(sw, settings))
Then, it invokes the WriteStartDocument method on the XmlWriter to mark the beginning of the
XML document:
xw.WriteStartDocument();
c01.indd 18c01.indd 18 8/20/07 5:40:10 PM8/20/07 5:40:10 PM