Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.

Similar presentations


Presentation on theme: " 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message."— Presentation transcript:

1  2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message Forum Documents 34.3 Forum Navigation 34.4 Adding Forums 34.5 Forum XML Documents 34.6 Posting Messages 34.7 Other Documents 34.8 Web Resources

2  2004 Prentice Hall, Inc. All rights reserved. 2 Objectives In this tutorial, you will learn: –To create a Web-based message forum using Active Server Pages. –To use XML with Active Server Pages. –To be able to add new forums. –To be able to post messages to the message forum. –To use Microsoft’s DOM to manipulate an XML document. –To use XSLT to transform XML documents.

3  2004 Prentice Hall, Inc. All rights reserved. 3 34.1 Introduction Message forums –Popular internet feature –Discuss topics –Exchange information –Several major sites provide this service messages.yahoo.com/index.html web.eesite.com/forums groups.google.com

4  2004 Prentice Hall, Inc. All rights reserved. 4 34.2 Setup and Message Forum Documents Prerequisites –Microsoft Internet Information Services 6 (IIS) –Internet Explorer 6 (for XML and XSLT processing) –MSXML 3.0 or higher –Write permissions on forum folder

5  2004 Prentice Hall, Inc. All rights reserved. 5 34.2 Setup and Message Forum Documents

6  2004 Prentice Hall, Inc. All rights reserved. 6 34.3 Forum Navigation default.asp addForum.asp forums.xml forumASP.xml addPost.asp formatting.xsl Fig. 34.2 Key interactions between message forum documents.

7  2004 Prentice Hall, Inc. All rights reserved. 7 34.2 Setup and Message Forum Documents Forum listing –XML –filename attribute

8  2004 Prentice Hall, Inc. All rights reserved. Outline 8 forums.xml (1 of 1) Name of forum. XML document that contains the information for forum ASP.

9  2004 Prentice Hall, Inc. All rights reserved. 9 34.2 Setup and Message Forum Documents Presenting forum listing –Convert to XHTML –CSS for formatting –ASP facilitates the conversion DOMDocument Async property DocumentElement ChildNodes For Each…Next control structure

10  2004 Prentice Hall, Inc. All rights reserved. Outline 10 default.asp (1 of 3) Link to CSS style sheet style.css.

11  2004 Prentice Hall, Inc. All rights reserved. Outline 11 default.asp (2 of 3) Instantiate an XML DOM object.Setting Async to False causes the object referenced by xmlFile to behave synchronously. Method Load parses the XML document forums.xml.If the parsing fails, the browser is redirected to invalid.html. Property DocumentElement gets the root element’s child nodes. Property ChildNodes returns a collection of the element node’s child nodes. Method getAttribute gets a forum’s filename. The anchor element creates a link to the available forums.

12  2004 Prentice Hall, Inc. All rights reserved. Outline 12 default.asp (3 of 3) This anchor element links to the ASP document addForum.asp that allows the user to create a new forum.

13  2004 Prentice Hall, Inc. All rights reserved. 13 34.3 Forum Navigation Fig. 34.4 Message forums main page.

14  2004 Prentice Hall, Inc. All rights reserved. 14 34.3 Adding Forums Template forum –Bare minimum elements of forum –stylesheet tag for formatting –forum tag

15  2004 Prentice Hall, Inc. All rights reserved. Outline 15 template.xml The stylesheet processing instruction references formatting.xsl.

16  2004 Prentice Hall, Inc. All rights reserved. 16 34.3 Adding Forums Generating forum from template –Form to get information on new forum Name and file name User name Message title and text –Script to act on form input Confirm valid input SetAttribute –filename –timestamp CreateElement AppendChild Save

17  2004 Prentice Hall, Inc. All rights reserved. Outline 17 addForum.asp (1 of 7) Check to see if a value was entered in each of the form fields. Test to see if the form was submitted by testing the form’s submit field for a value.

18  2004 Prentice Hall, Inc. All rights reserved. Outline 18 addForum.asp (2 of 7) Method Load loads the template XML document. Method setAttribute creates an attribute node named filename that has the value contained in form field filename. Method AppendChild appends the newly created element name node to the root element.

19  2004 Prentice Hall, Inc. All rights reserved. Outline 19 addForum.asp (3 of 7) Calling method Save saves the XML document to disk. Open XML document forums.xml.

20  2004 Prentice Hall, Inc. All rights reserved. Outline 20 addForum.asp (4 of 7) Modify forums.xml. Save forums.xml with its new contents to disk.

21  2004 Prentice Hall, Inc. All rights reserved. Outline 21 addForum.asp (5 of 7) This XHTML form allows a user to input the name, filename, a user name, a message title and the message text to create a new forum.

22  2004 Prentice Hall, Inc. All rights reserved. Outline 22 addForum.asp (6 of 7)

23  2004 Prentice Hall, Inc. All rights reserved. Outline 23 addForum.asp (7 of 7) The Submit button submits the form and the values input in the form fields. The Clear button will delete all values in the form fields.

24  2004 Prentice Hall, Inc. All rights reserved. 24 34.3 Adding Forums Fig. 34.6 Page to add a forum.

25  2004 Prentice Hall, Inc. All rights reserved. 25 34.5 Forum XML Documents Sample forum –XML modified with several forums added –XSLT used to transform XML –Final XHTML page served to Internet Explorer

26  2004 Prentice Hall, Inc. All rights reserved. Outline 26 forumASP.xml (1 of 2) The name of the forum.Each message element and its children contain the information for a post.

27  2004 Prentice Hall, Inc. All rights reserved. Outline 27 forumASP.xml (2 of 2)

28  2004 Prentice Hall, Inc. All rights reserved. Outline 28 formatting.xsl (1 of 4) Element xsl:stylesheet is the XSLT document’s root element. Attribute version specifies the XSLT version to which this style sheet conforms. The attribute xmlns creates a namespace prefix xsl. The xsl:output element specifies how the result tree is output. Attribute method is assigned html, which specifies that an XHTML document is being output. Attribute omit-xml- declaration is assigned no, which results in an XML declaration in the result tree. Select the template that match es the XML document root ( / ). The asterisk selects element nodes.

29  2004 Prentice Hall, Inc. All rights reserved. Outline 29 formatting.xsl (2 of 4) Link to the CSS style sheet style.css. Get value of name element. Apply message template.

30  2004 Prentice Hall, Inc. All rights reserved. Outline 30 formatting.xsl (3 of 4) Get the value of attribute filename. Begin template message.Get value of user element.

31  2004 Prentice Hall, Inc. All rights reserved. Outline 31 formatting.xsl (4 of 4) Get value of attribute timestamp. Get value of text element.

32  2004 Prentice Hall, Inc. All rights reserved. Outline 32 forumASP_transformed.html (1 of 3) Forum title.Message title.

33  2004 Prentice Hall, Inc. All rights reserved. Outline 33 forumASP_transformed.html (2 of 3) Message author.Time and date posted. Message text.

34  2004 Prentice Hall, Inc. All rights reserved. Outline 34 forumASP_transformed.html (3 of 3) Link to add a new post.

35  2004 Prentice Hall, Inc. All rights reserved. 35 34.5 Forum XML Documents Fig. 34.9 Output of the transformation of the forum XML document.

36  2004 Prentice Hall, Inc. All rights reserved. 36 34.6 Posting Messages Posting a message –Procedure similar to creating new forum

37  2004 Prentice Hall, Inc. All rights reserved. Outline 37 addPost.asp (1 of 5) Test to see if the form was submitted by testing the form’s submit field for a value. Check to see if a value was entered in each of the form fields. Method Load loads the forum XML document.

38  2004 Prentice Hall, Inc. All rights reserved. Outline 38 addPost.asp (2 of 5) Create a message node. Create a timeStamp attribute for the message node. Create the children of the message node: user, title and text.

39  2004 Prentice Hall, Inc. All rights reserved. Outline 39 addPost.asp (3 of 5)

40  2004 Prentice Hall, Inc. All rights reserved. Outline 40 addPost.asp (4 of 5) This form allows the user to create a post by entering the values into the form fields.

41  2004 Prentice Hall, Inc. All rights reserved. Outline 41 addPost.asp (5 of 5)

42  2004 Prentice Hall, Inc. All rights reserved. 42 34.6 Posting Messages Fig. 34.10 Adding a message to a forum.

43  2004 Prentice Hall, Inc. All rights reserved. 43 34.6 Posting Messages Fig. 34.11 New forum on the message board.

44  2004 Prentice Hall, Inc. All rights reserved. 44 34.6 Posting Messages Fig. 34.12 Initial content of the newly added forum.

45  2004 Prentice Hall, Inc. All rights reserved. 45 34.6 Posting Messages Fig. 34.13 Contents of the Internet and World Wide Web: Third Edition forum.

46  2004 Prentice Hall, Inc. All rights reserved. 46 34.7 Other Documents Other documents required by forum –Error page –CSS for formatting XHTML Forums

47  2004 Prentice Hall, Inc. All rights reserved. Outline 47 invalid.html (1 of 1) Link that references CSS style sheet site.css.

48  2004 Prentice Hall, Inc. All rights reserved. Outline 48 site.css (1 of 3) Define styles for the body element.Define styles for the anchor element.Define styles for the table element.

49  2004 Prentice Hall, Inc. All rights reserved. Outline 49 site.css (2 of 3)

50  2004 Prentice Hall, Inc. All rights reserved. Outline 50 site.css (3 of 3)

51  2004 Prentice Hall, Inc. All rights reserved. Outline 51 style.css (1 of 5) Define styles for the h1 element.Define styles for the h2 element.Define styles for the p element.

52  2004 Prentice Hall, Inc. All rights reserved. Outline 52 style.css (2 of 5) Define styles for the body element.Define styles for the li element.

53  2004 Prentice Hall, Inc. All rights reserved. Outline 53 style.css (3 of 5) Define styles for the input element. Define styles for the textarea element.

54  2004 Prentice Hall, Inc. All rights reserved. Outline 54 style.css (4 of 5)

55  2004 Prentice Hall, Inc. All rights reserved. Outline 55 style.css (5 of 5)


Download ppt " 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message."

Similar presentations


Ads by Google