You should first be familiar with the elements in the
XML document. This means that you should know the tag names and the
relationships among the elements. This is because, in your style sheet, you
will create a style for each desired tag and you will use the name of that
style. Consider the following XML document that we saw earlier: <?xml version="1.0" encoding="UTF-8"?> <Employees> <Employee> <FirstName>Frank</FirstName> <LastName>Misma</LastName> <DateHired>10/04/2008</DateHired> <Title>General Manager</Title> </Employee> <Employee> <FirstName>Justine</FirstName> <LastName>Grand</LastName> <DateHired>05/30/2012</DateHired> <Title>Sales Associates</Title> <HourlySalary>22.15</HourlySalary> </Employee> <Contractor> <FullName>Arnold Alley</LastName> <Job>Webmaster</Job> </Contractor> </Employees> Based on the names of its elements (FirstName, LastName, DateHired, etc), you can create a style sheet for it as follows: FirstName, LastName { font-family: Verdana, Geneva, Tahoma, sans-serif; font-size: 12pt; color: red; } FullName { font-family: Verdana, Geneva, Tahoma, sans-serif; font-size: 14pt; color: blue; background-color: orange; } DateHired { font-family: Verdana, Geneva, Tahoma, sans-serif; font-size: 12pt; color: green; } Title, Job { font-family: Verdana, Geneva, Tahoma, sans-serif; font-size: 12pt; color: maroon; } HourlySalary { font-family: Verdana, Geneva, Tahoma, sans-serif; font-size: 12pt; color: orange; } Save the document as a file with the .css extension. To specify the style sheet, in the XML file, set the type as text/css: <?xml-stylesheet href="File Name or Path.css" type="text/css"?>
Replace File Name or Path with either the name of the file or the complete path and file name. Here is an extension: Private Sub cmdCascadingStyleSheet_Click() On Error GoTo cmdCascadingStyleSheet_Error Open "Employees8.css" For Output As #1 Print #1, "FirstName, LastName {" Print #1, "font-family: Verdana, Geneva, Tahoma, sans-serif;" Print #1, "font-size: 12pt;" Print #1, "color: red;" Print #1, "}" Print #1, "FullName {" Print #1, "font-family: Verdana, Geneva, Tahoma, sans-serif;" Print #1, "font-size: 14pt;" Print #1, "color: blue;" Print #1, "background-color: orange;" Print #1, "}" Print #1, "DateHired {" Print #1, "font-family: Verdana, Geneva, Tahoma, sans-serif;" Print #1, "font-size: 12pt;" Print #1, "color: green;" Print #1, "}" Print #1, "Title, Job {" Print #1, "font-family: Verdana, Geneva, Tahoma, sans-serif;" Print #1, "font-size: 12pt;" Print #1, "color: maroon;" Print #1, "}" Print #1, "HourlySalary {" Print #1, "font-family: Verdana, Geneva, Tahoma, sans-serif;" Print #1, "font-size: 12pt;" Print #1, "color: orange;" Print #1, "}" Close #1 Exit Sub cmdCascadingStyleSheet_Error: MsgBox "There was a problem when trying to create the CSS file.", _ vbOKOnly Or vbInformation, _ "Extensible Markup Language" Resume Next End Sub Private Sub cmdUsingCascadingStyleSheet_Click() On Error GoTo cmdUsingCascadingStyleSheet_Error Open "Employees8.xml" For Output As #1 Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>" Print #1, "<?xml-stylesheet href=""Employees7.css"" type=""text/css""?>" Print #1, "<Employees>" Print #1, " <Employee>" Print #1, " <FirstName>Frank</FirstName>" Print #1, " <LastName>Misma</LastName>" Print #1, " <DateHired>10/04/2008</DateHired>" Print #1, " <Title>General Manager</Title>" Print #1, " </Employee>" Print #1, " <Employee>" Print #1, " <FirstName>Justine</FirstName>" Print #1, " <LastName>Grand</LastName>" Print #1, " <DateHired>05/30/2012</DateHired>" Print #1, " <Title>Sales Associates</Title>" Print #1, " <HourlySalary>22.15</HourlySalary>" Print #1, " </Employee>" Print #1, " <Contractor>" Print #1, " <FullName>Arnold Alley</FullName>" Print #1, " <Job>Webmaster</Job>" Print #1, " </Contractor>" Print #1, "</Employees>" Close #1 Exit Sub cmdUsingCascadingStyleSheet_Error: MsgBox "There was a problem when trying to create the XML file.", _ vbOKOnly Or vbInformation, _ "Extensible Markup Language" Resume Next End Sub This would produce |
|
|
|