Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 451: USING ASP.NET TO CREATE XML Dr. Ralph D. Westfall February, 2009.

Similar presentations


Presentation on theme: "CIS 451: USING ASP.NET TO CREATE XML Dr. Ralph D. Westfall February, 2009."— Presentation transcript:

1 CIS 451: USING ASP.NET TO CREATE XML Dr. Ralph D. Westfall February, 2009

2 Creating XML with a Program create ASP.NET page with controls with Visual Web Developer Express or use an HTML form with input areas use text input fields (1 line) for short items use textareas for longer inputs specify # of rows and columns set wrap = on

3 UI and Code File add 6 TextBoxes to Default.aspx set TextMode to Multiline on TextBox5 put a Button after the 5 th TextBox click Button to create sub in Default.aspx.vb put Imports System.IO as first line declare objSW as a StreamWriter object

4 Code File - 2 declare/instantiate the following Strings strFile, strName, strStreet, strCity, strComments assign TextBox[].Text values to the above Dim strQt = Chr(34) ' a single quote add a folder named xml to project right click project in Solution Explorer, select New Folder, rename it xml

5 Code - 3 Dim strFullPath as String = Request.PhysicalApplicationPath & "xml\" & strFile & ".xml" 'period add a Try/Catch block Try Catch err As Exception TextBox6.Text = "Error: " & err.Message End Try

6 Code - 4 put file writing code in the Try block objSW = File.CreateText(strFullPath) write XML header objSW.WriteLine("<?xml version=" _ & strQt & "1.0" & strQt & " ?>") write XML root tag objSW.WriteLine(" ")

7 Code - 5 write file lines objSW.WriteLine(" " _ & strName & " ") objSW.WriteLine(" " _ & strStreet & " ") write closing tag objSW.WriteLine(" ")

8 Code and UI End Try block and close.xml file after finished writing lines to it objSW.Close go back to Default.aspx drag and drop a hyperlink onto form delete its Text property

9 Configure Link to XML File put the following code after End Try statement in Default.aspx.vb strFile &= ".xml" HyperLink1.Text = strFile HyperLink1.NavigateUrl = "xml\" & strFile

10 Run Default.aspx Click the link to view the xml file if the link doesn't load the.xml page, go to the xml subdirectory in Solution Explorer and uncheck Read Only could also right click the xml folder in Solution Explorer, select Refresh Folder and then double click the xml file name

11 Exercise see makereport.aspx for code generated by these instructionsmakereport.aspx add more/different input controls to Default.aspx modify code to write their contents into XML also add elements with sub-elements test code, correct as necessary

12 Exercise - 2 create DTD and CSS files to work with the XML files that your code is writing put them into the directory that the XML files are being written to modify the code in Default.aspx to write the links to these files into the XML files


Download ppt "CIS 451: USING ASP.NET TO CREATE XML Dr. Ralph D. Westfall February, 2009."

Similar presentations


Ads by Google