-
Notifications
You must be signed in to change notification settings - Fork 52
/
Demo.aspx
75 lines (71 loc) · 2.38 KB
/
Demo.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<%@PAGE LANGUAGE=C# debug="true" validateRequest=false %>
<%@Import Namespace="System"%>
<%@Import Namespace="System.Xml"%>
<%@Import Namespace="System.Xml.Schema"%>
<%@Import Namespace="System.IO"%>
<%@Import Namespace="Sgml"%>
<html>
<style>
h2 { border-left: 10 solid navy; border-top: 1 solid navy; padding-left:15; }
</style>
<script runat="server">
string SgmlReaderTest(Uri baseUri, string html, TextWriter log, bool upper, bool formatted)
{
try {
SgmlReader r = new SgmlReader();
r.SetBaseUri(Server.MapPath("."));
r.DocType = "HTML";
r.InputStream = new StringReader(html);
if (upper) r.CaseFolding = CaseFolding.ToUpper;
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
if (formatted) {
w.Formatting = Formatting.Indented;
r.WhitespaceHandling = WhitespaceHandling.None;
}
while (!r.EOF) {
w.WriteNode(r, true);
}
w.Close();
return sw.ToString();
} catch (Exception e) {
return e.ToString();
}
}
void SubmitBtn_Click(Object Src, EventArgs E)
{
StringWriter log = new StringWriter();
bool upper = (Request.Form["UPPER"] == "on");
bool formatted = (Request.Form["PRETTY"] == "on");
string result = SgmlReaderTest(
new Uri("file://"+Server.MapPath(".")),
DATA.InnerText, log, upper, formatted);
XML.InnerText = result;
}
</script>
<h2>SgmlReader Demo</h2>
<form runat="server" method="POST" action="demo.aspx">
<h4 style="margin:0;background-color:navy;color:white">HTML</h4>
<textarea runat="server" rows=10 cols=70 id=DATA>
<html><body>
<!-- This typical SGML document contains unclosed tags,
unquoted attributes, attributes with no values,
duplicate attributes, and mismatched end tags -->
<table width=200>
<tr><td align=left>
<tr><td><input type=checkbox checked>
<tr><td align=left align=right>
</table>
</html>
</textarea>
<h4 style="margin:0;background-color:navy;color:white">XML</h4>
<textarea runat="server" rows=20 cols=70 id=XML></textarea>
<br/>
<asp:button text="SUBMIT" Onclick="SubmitBtn_Click" runat=server/>
<asp:checkbox text="Upper case" id="UPPER" runat=server/>
<asp:checkbox text="Pretty print" id="PRETTY" runat=server/>
<br/><br/>
See <a href="/srcview/srcview.aspx?path=/tools/sgmlreader/sgmlreader.src&file=Demo.aspx">Source Code</a>
for this page.
</form>
</html>