Web Analytics Made Easy -
StatCounter Can anyone help me with my ASP.NET project? - CodingForum

Announcement

Collapse
No announcement yet.

Can anyone help me with my ASP.NET project?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can anyone help me with my ASP.NET project?

    I have this guestBook (guestbook.aspx), the posts (posts.xml) and the formatting of the output (formatting.xsl).

    I want to be able to search the xml file using a form with one textfield and a button to start the search. When the search is done, the results shown on the page. But I have problems:

    1. I don't know how to search the xml file;
    2. I don't know how to display only parts from the xml (ex.: search for: Dean, and every node that has this word will be displayed)

    This is the guestbook.aspx file:


    <%@ Page Language="JScript" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Xml" %>

    <html>
    <head>
    <title>DENIDA - GuestBook</title>
    <script languiage="JScitpt" runat="server">
    function guestBookPost_Click(sender: Object, events: EventArgs):void
    {
    var myDocument : XmlDocument = new XmlDocument();
    myDocument.Load( Server.MapPath("posts.xml"));

    var postNode:XmlElement = myDocument.CreateElement("post");
    postNode.SetAttribute("timestamp", DateTime.Now.ToString());

    var nameNode:XmlElement = myDocument.CreateElement("name");
    var emailNode:XmlElement = myDocument.CreateElement("email");
    var messageNode:XmlElement = myDocument.CreateElement("message");
    var dividerNode:XmlElement = myDocument.CreateElement("divider");

    nameNode.AppendChild(myDocument.CreateTextNode(name.Text));
    emailNode.AppendChild(myDocument.CreateTextNode(email.Text));
    messageNode.AppendChild(myDocument.CreateTextNode(message.Text));
    dividerNode.AppendChild(myDocument.CreateTextNode(" - "));

    postNode.AppendChild(nameNode);
    postNode.AppendChild(emailNode);
    postNode.AppendChild(messageNode);
    postNode.AppendChild(dividerNode);

    myDocument.DocumentElement.PrependChild(postNode);
    myDocument.Save(Server.MapPath("posts.xml"));

    name.Text = "";
    email.Text = "";
    message.Text = "";

    Response.Redirect("posts.xml");
    }
    </script>
    <link href="file:///D|/back up/my docs/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    .style1 {font-size: xx-small}
    .style2 {font-size: x-small}
    -->
    </style>
    </head>
    <body>
    <form class="style1" runat="server">
    <table width="341" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="341"><br />
    <table>
    <tr>
    <td><span class="style2">Name:</span></td><td><span class="style1">
    <asp:TextBox ID="name" Columns="25" runat="server" CssClass="txt"/>
    </span></td></tr>
    <tr><td><span class="style2">E-mail:</span></td><td><span class="style1">
    <asp:TextBox Columns="25" ID="email" runat="server" CssClass="txt" />
    </span></td></tr>
    </table>
    <span class="style2">Message:
    <asp:TextBox ID="message" Columns="40" Rows="4" runat="server" TextMode="MultiLine"/>
    <br />
    <asp:LinkButton ID="guestBookPost" OnClick="guestBookPost_Click" Text="Post" runat="server"/>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <asp:HyperLink ID="link" NavigateUrl="posts.xml" Text="View" runat="server" /> </span>
    </form>
    </body>
    </html>



    This is the formatting.xsl file:

    <?xml version = "1.0" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
    <xslutput method="html" omit-xml-declaration = "no" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" doctype-public="-//W3C//DTD XHTML 1.1//EN" />
    <xsl:template match = "/">
    <html xmlns="http:///www.w3.org/1999/xhtml">
    <xsl:apply-templates select="*" />
    </html>
    </xsl:template>
    <xsl:template match="guestbook">
    <head>
    <title><xsl:value-of select="name"/></title>
    <link rel="stylesheet" type="text/css" href="file:///D|/back up/my docs/style.css" />
    </head>
    <body>
    <table width="100%" cellpadding="2">
    <xsl:apply-templates select="post" />
    </table>
    <p>
    <a href="file:///D|/back up/my docs/denida/guestbook.aspx">Post a message!</a>
    </p>
    </body>
    </xsl:template>
    <xsl:template match="post">
    <tr>
    <td>
    <b><em><a href="mailto:{email}"><xsl:value-of select="name" /></a></em></b><xsl:value-of select="divider" /><xsl:value-of select="@timestamp" />
    </td>
    </tr>
    <tr>
    <td>
    <xsl:value-of select = "message" />
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>

    And this is the posts.xml file:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="formatting.xsl"?>
    <guestbook>
    <post timestamp="01.10.2006 15:05:43">
    <name>Dean Kocevski</name>
    <email>[email protected]</email>
    <message>Hello!!!!!!!!!!</message>
    <divider> - </divider>
    </post>
    <post timestamp="8/4/2006 5:46:36 PM">
    <name>borce</name>
    <email>[email protected]</email>
    <message>ha ha ha </message>
    <divider> - </divider>
    </post>
    <post timestamp="8/4/2006 1:31:02 AM">
    <name>Dean Kocevski</name>
    <email>[email protected]</email>
    <message>I hope that you'll leave your honest comments here... I want to know what do you think about the site...so the guestbook is yours....</message>
    <divider> - </divider>
    </post>
    </guestbook>


    Any help is appreciated!!!!!!!

    Regards, Lallo!

Working...
X