Home

Characteristics of XML Elements

XML Attributes

Introduction

We have learned to create an element by specifying a start tag and an optional end tag. We also know that, to specify the value of an element, we can type it outside the start tag of the element. If we want to add a child node, we can nest a complete element with a start tag, an optional name and an optional value. An XML attribute is a technique to create a start tag that includes the child node(s) of the tag in the start tag. This means that the child nodes are not created with their own tag: they are embedded in the start tag of the element.

Creating an Attribute

To create an XML attribute, inside the start tag, after the name of the element, type the name of each attribute and assign the desired value to it, using the assignment operator "=". The name of the attribute follows the same rules of the names of elements. The value of the attribute must be in double-quotes. Here are two examples of elements each with an attribute:

<Employee FirstName="Frank"></Employee>
<Employee FirstName="Justine" />

Of course, an element can still have its own value, in which case the value is typed outside the start tag and the element must have an end tag. Here is an example:

<Employee FirstName="Frank">Is about to lead a new division.</Employee>

An Element With Many Attributes

The start tag of an element can contain many attributes. Each attribute is created with a value assigned to its name. Here are examples:

<?xml version="1.0" encoding= UTF-8 ?>"
<Employees>
  <Employee FirstName="Frank" LastName="Misma" Title="General Manager" DateHired="10/04/2008"></Employee>
  <Employee DateHired="05/30/2012" LastName="Grand" FirstName="Justine" Title="Sales Associates" />
  <Contractor FullName="Arnold Alley" Job="Webmaster">
    <HourlySalary>25.50</HourlySalary>
  </Contractor>
</Employees>

To make the attributes easy to read, you can write each on its own line and indent them on the same level. Here are examples:

<?xml version="1.0" encoding= UTF-8 ?>"
<Employees>
  <Employee FirstName="Frank"
            LastName="Misma"
            Title="General Manager"
            DateHired="10/04/2008">
  </Employee>
  <Employee DateHired="05/30/2012"
            LastName="Grand"
            FirstName="Justine"
            Title="Sales Associates" />
  <Contractor FullName="Arnold Alley"
              Job="Webmaster">
    <HourlySalary>25.50</HourlySalary>
  </Contractor>
</Employees>

Of course, you can create attributes using VBA code. Here are examples:

Private Sub cmdXMLElement_Click()
On Error GoTo cmdElement_Error

    Open "Employees5.xml" For Output As #1

    Print #1, "<?xml version="1.0" encoding= UTF-8 ?>"
    Print #1, "<Employees>"
    Print #1, "  <Employee FirstName='Frank' LastName='Misma' Title='General Manager'>"
    Print #1, "    <DateHired>10/04/2008</DateHired>"
    Print #1, "  </Employee>"
    Print #1, "  <Employee DateHired='05/30/2012' LastName='Grand' FirstName='Justine' Title='Sales Associates' />"
    Print #1, "  <Contractor FullName='Arnold Alley'>"
    Print #1, "    <Job>Webmaster</Job>"
    Print #1, "    <HourlySalary>25.50</HourlySalary>"
    Print #1, "  </Contractor>"
    Print #1, "</Employees>"

    Close #1
    
    Exit Sub

cmdElement_Error:
    MsgBox "There was a problem when trying to create the XML file.", _
         vbOKOnly Or vbInformation, _
         "Extensible Markup Language"
    Resume Next
End Sub

Notice that the first and the second <Employee> elements share some attributes but also notice how "messy" they are. For example, in the first <Employee> element, the FirstName attribute comes before the LastName, which is reversed on the second <Employee> element. Also notice that the first <Employee> element contains a child element named DateHired, but DateHired is created as an attribute in the second <Employee> element.

On one hand, you are free to create your child elements and attributes any way you want. On the other hand, you should be better organized. For example, on elements that are on the same level, if they have the same child element, either create it as a child element or as an attribute. This is not a rule but a suggestion. The other suggestion you should apply to attributes is their order. Again, this is not a rule but an attribute shared by elements on the same level should be in the same positions. For example, if the first and the second elements have many attributes and one of those attributes is named FirstName, if you decide to use that attribute as the first, use it like that on all elements that have that attribute. The reason is that if you must right code that looks for an attribute and you try to locate the attribute by position, your code would process better if the attributes on the same positions have the same name.

So far, we have learned how to create elements, that is, how to create:

That's all you need to know to create a fully-functional XML database. The features we will review now are additional options that can be helpful, but are not required.

Introduction to Features of XML

Comments

A comment is a section that the parser must ignore in the XML document. To create a commented line, type <!--, followed by the comment you want, and end it with --> Here are examples:

Private Sub cmdComment_Click()
On Error GoTo cmdElement_Error

    Open "Employees5.xml" For Output As #1

    Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
    Print #1, "<Employees>"
    Print #1, "  <Employee>"
    Print #1, "  <!-- This is the employee who started the company. -->"
    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, "  <!-- This is an approximate date. -->"
    Print #1, "  <!-- No one remembers when this employee started. -->"
    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

cmdElement_Error:
    MsgBox "There was a problem when trying to create the XML file.", _
         vbOKOnly Or vbInformation, _
         "Extensible Markup Language"
    Resume Next
End Sub

Characters in Data: CDATA

CDATA is XML data included in an XML document but the parser must ignore its section when processing the content of the document. To create a CDATA section, start it with <![CDATA[ and end with ]]>. Any XML code between those two sections will not be processed by the parser, but that XML code should still be well-formed. Here is an example:

Private Sub cmdCDATASection_Click()
On Error GoTo cmdCDATASection_Error

    Open "Employees6.xml" For Output As #1

    Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
    Print #1, "<Employees>"
    Print #1, "  <Employee>"
    Print #1, "    <FirstName>Frank</FirstName>"
    Print #1, "    <LastName>Misma</LastName>"
    Print #1, "    <![CDATA[<FullName>LastName, FirstName</FullName>]]>"
    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

cmdCDATASection_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:

<?xml version="1.0" encoding="UTF-8" ?> 
<Employees>
  <Employee>
    <FirstName>Frank</FirstName> 
    <LastName>Misma</LastName> 
    <![CDATA[ <FullName>LastName, FirstName</FullName>]]>
    <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</FullName> 
    <Job>Webmaster</Job> 
  </Contractor>
</Employees>

While the above CDATA section was created on only one line, you can create a CDATA section that covers as many lines as you want. There are two rules to follow:

Here is an example:

Private Sub cmdCDATASection_Click()
On Error GoTo cmdCDATASection_Error

    Open "Employees7.xml" For Output As #1

    Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
    Print #1, "<Employees>"
    Print #1, "<!-- This is the primary structure of our XML document. -->"
    Print #1, "<![CDATA["
    Print #1, "<Employees>"
    Print #1, "  <Employee>"
    Print #1, "    <FirstName></FirstName>"
    Print #1, "    <LastName></LastName>"
    Print #1, "    <DateHired></DateHired>"
    Print #1, "    <Title></Title>"
    Print #1, "  </Employee>"
    Print #1, "</Employees>"
    Print #1, "]]>"
    Print #1, "  <Employee>"
    Print #1, "    <FirstName>Frank</FirstName>"
    Print #1, "    <LastName>Misma</LastName>"
    Print #1, "    <![CDATA[<FullName>LastName, FirstName</FullName>]]>"
    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

cmdCDATASection_Error:
    MsgBox "There was a problem when trying to create the XML file.", _
         vbOKOnly Or vbInformation, _
         "Extensible Markup Language"
    Resume Next
End Sub

XML Namespaces

In a computer program, a file (such as a Visual Basic module) that holds code can contain declared variables, functions (or procedures), class, etc.

Private IsReady As Boolean

Public Sub CreateListing()

End Sub 

Public Function Sell() As Currency

End Function

Class House
  Public Price As Double

  Public Sub Build()

  End Sub
End Class

You can then use the variables, functions, and classes in another part of the project. For example, you can access a variable based on its name. You can call a function using its name. You can declare a variable of the class:

Dim PropertyOnLockwoodDrive As House

Dim SaleResult As Currency

SaleResult = Sell()

The name of each item in the file must be unique (two items in the module cannot have the same name). If two items have the same name, there would be a name conflict that would lead to an error:

Private IsReady As Boolean

Private IsReady As Boolean ' Error: A variable named IsReady exists already

Public Sub CreateListing()

End Sub 

Public Function Sell() As Currency

End Function

Class House
  Public Price As Double

  Public Sub Build()

  End Sub
End Class

Class House ' Error: A class named House exists already

End Class

If you need to use the same names for different items, one solution is to create different sections in a file, give a name to each section, and create items inside the desired section and/or functions that must be isolaled. A namespace is a group of isolated items. The items in the group are distinguished by their belonging to their unique group.

In most computer languages like Visual Basic (the modern version), C#, or C++, a namespace is primarily created as a section of code in a document and the namespace is given a name. The area of the namespace is delimited one way or another:

Namespace AuroraBuilders
Private IsReady As Boolean

Public Sub CreateListing()

End Sub 

Public Function Sell() As Currency

End Function

Class House
  Public Price As Double

  Public Sub Build()

  End Sub
End Class

End Namespace

' Blah Blah Blah

Namespace JoshuaConstruction
Private IsReady As Boolean ' No Error: The variable named IsReady is unique in this namespace

Class House ' No Error: There is no other class named House in this namespace

End Class

Class Car

End Class
End Namespace

Each computer language has its own rules as to how to create a namespace. In C# and C++, you start with the namespace keyword followed by a name. Then, the area of the namespace is delimited with { and }. In Visual Basic, the area of the namespace starts with the keyword Namespace followed by a name and ends with a line marked End Namespace. In some other programming languages (such as Java that uses the word Package), a namespace is created in its own file such as a web document.

When an item belongs to a namespace, to access that item outside its namespace, you must qualify its name. That is, you must indicate to what namespace the item belongs. The way you do this depends in the language you are using. In some languages, you must first "import" the namespace. In C#, this is done by typing using, followed by the name of the namespace, and a semi-colon. In C++, you type using namespace, followed by the name of the namespace, and a semi-colon. In Visual Basic, you type Imports and in Java (remember that Java doesn't have namespaces per se, Java has packages) you use import, followed by the name of the namespace (or package), and a semi-colon. There are many other issues to take into consideration but these would be enough for now. Here is an example of how names of objects can be qualified from their namespaces:

Dim PropertyOnLockwoodDrive As AuroraBuilders.House
Dim BeltsvilleCondo As JoshuaConstruction.House

AuroraBuilders.CreateListing()

Dim SaleResult As Currency

SaleResult = AuroraBuilders.Sell()

Dim UsedVehicle As JoshuaConstruction.Car

As mentioned already, instead of the period, some other languages use other means to access the member of a namespace. For example, C++ uses the double-colon :: while another language may use only one colon :. Also, in most languages, if you have already imported a namespace, if you use a name that belongs to only one namespace, in other words there may not be name conflict, you may not have to qualify the name of an object:

Imports AuroraBuilders
Imports JoshuaConstruction

Dim PropertyOnLockwoodDrive As AuroraBuilders.House

CreateListing()

Dim SaleResult As Currency

SaleResult = Sell()

Dim BeltsvilleCondo As JoshuaConstruction.House

Dim UsedVehicle As Car

An XML namespace is a Web document (as a Web page) that specifies the document where the elements and attributes (almost like classes and functions of our example) of an XML document are defined. This means that you must first create an XML namespace document in a Web document, save it as a Web file (which usually has the extension .htm, or .html, or else), upload it to a web server, and get or know its Web address, named a URI. An example of such an address would be http://www.functionx.com/Houses. Then, in the XML document that references the namespace, each element that uses, or belongs to, that namespace must be qualified. This is done by writing the name of the namespace, followed by a colon ":" (in C# and Visual Basic, the period is used; in C++, the double-colon :: is used), and followed by the name of the element or the name of the attibute. You must also give the address, called URI, of the Web page. To do this, type xmlns, followed by a colon, followed by the name of the element or attribute to which you would assign the address as a string. The formula to follow is:

<Namespace:Element/Attribute xmlns:Namespace="URI">

After the traditional < symbol, you start with the name of the namespace followed by a colon and the name of your local element or attribute. This is followed by a space, xmlns:, and the name of the namespace assigned the address the document where the namespace is designed.

In most cases, you will hardly, if ever, create your own namespaces. Instead, you will use the namespaces already defined by W3C or namespaces created by companies such as Microsoft, etc.

XML Schemas

Introduction

An XML schema is a document that gives instructions to the parser about the contents or structure of an XML document (XML schema structure is defined by the W3C at http://www.w3.org/TR/xmlschema-1/). The document specifies how the elements and attributes are defined and declared in the XML document. For example, a schema can:

The parser can then refer to the schema when processing the XML document.

XML Schema Document Declaration

An XML schema starts as a regular XML file, with an XML declaration. Here is an example:

<?xml version="1.0" encoding="UTF-8"?>

This is followed by a special element. The name of that element is made of two parts: a prefix for the elements in the XML schema document, followed by :schema. The prefix can be one letter such as a, b, c, or else. Here is an example:

<a:schema></a:schema>

The prefix can also be made of 2, 3, or more letters. In fact, it can be a whole word or name. The element must have one or more attributes. The one and required attribute must provide the XML namespace that holds information that the tags in the XML schema document will need. For example, the XML schema is defined in http://www.w3.org/2001/XMLSchema. To add it, create an attribute whose name is made of xmlns: followed by the prefix you had defined, and assign the XML Schema address to that attribute. This can be done as follws:

<a:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"></a:schema>

After creating the document, save it as a file with an extention of .xsd. You should then reference that file in your XML document.

To distinguish the types of values in an XML document, an XML schema considers two categories of values: simple types and complex types.

Simple Type Definition

For the purpose of XML schemas, a simple type element is one that includes a single value whose type is either created by you (we will see how) or defined in an XML namespace. The element whose schema you are defining can have neither attributes nor child elements. The formula to define a simple type element is:

<Prefix:element name="ElementName" [type="Data Type/Defined Type"/>

Or

<Prefix:element name="ElementName" [type="Data Type/Defined Type"></Prefix:element>

You start with the prefix you will have defined. This is followed by :element and the name keyword. Assign the name of the element whose schema you want to create. That name is passed as a string. Here is an example:

<a:element name="EmailAddress" />

This is enough to define a simple type element. If you define the type like that, the value of that element is assumed to be a string. Otherwise, you can (and should) specify the element's data type. XML's recognized data types, referred to as primitive and derived data types, have already been defined in a W3C document: http://www.w3.org/TR/xmlschema-2/.

Complex Type Definition

A complex type definition specifies the requirements of an element in an XML document. Such an element may have attributes and/or child elements. The basic formula to create a complex type definition is:

<Prefix:complexType name="ElementName">
  <Prefix:sequence>
    <Simple Type Definition>
    . . .
  </Prefix:sequence>
  <Prefix:attribute name="AttributeName" [type="Prefix:DataType"/>
  . . .
</Prefix:complexType

You start the definition with an element whose name is made of the prefix you will have defined, :, and the complexType keyword. You must close that tag at the end of the definition. Here is an example:

<a:complexType>
  . . .
</a:complexType

Between the start and the end tags, you must define the element, its child elements, and/or its attribute. If you want to define the child elements, start their section with a tag as <Prefix:sequence>, and make sure you close that tag. It is actually between this sequence start tag and its corresponding end tag that you define the child elements. Each child element is defined following the formula we saw for simple type definition.

Viewing an XML File

Using an Editor to Open an XML File

An XML file is primarily a text-based document. This means that you can open it using any text editor such as Notepad in Microsoft Windows or vi on UNIX/Linux. Most programming environments and HTML editors also make it possible to open an XML file. In fact, such applications make it possible to create and edit XML documents. While you as a database developer may open an XML document to explore its tags, a regular user would want to see a better display of the values in the document. In fact, most users are not interested in the structures of XML elements (their tags, etc). XML provides many options to aesthetically present XML to a regular user.

Previewing an XML File

Probably the easiest ways to see what an XML looks like is to use a Web browser. In most cases, if you double-click an XML file in a file utility such as Windows Explorer, this may launch the default browser and present the document. Consider the following file we saw earlier:

Private Sub cmdCDATASection_Click()
On Error GoTo cmdCDATASection_Error

    Open "Employees7.xml" For Output As #1

    Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
    Print #1, "<Employees>"
    Print #1, "<!-- This is the primary structure of our XML document. -->"
    Print #1, "<![CDATA["
    Print #1, "<Employees>"
    Print #1, "  <Employee>"
    Print #1, "    <FirstName></FirstName>"
    Print #1, "    <LastName></LastName>"
    Print #1, "    <DateHired></DateHired>"
    Print #1, "    <Title></Title>"
    Print #1, "  </Employee>"
    Print #1, "</Employees>"
    Print #1, "]]>"
    Print #1, "  <Employee>"
    Print #1, "    <FirstName>Frank</FirstName>"
    Print #1, "    <LastName>Misma</LastName>"
    Print #1, "    <![CDATA[<FullName>LastName, FirstName</FullName>]]>"
    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

cmdCDATASection_Error:
    MsgBox "There was a problem when trying to create the XML file.", _
         vbOKOnly Or vbInformation, _
         "Extensible Markup Language"
    Resume Next
End Sub

After the file has been created and saved, it can be previewed in a a Web browser as follows:

CDATA Section

Using a Cascading Style Sheet

To inform a parser as to how it should present an XML file in a Web browser, you can create a style sheet. In other words, a style sheet is a document that instructs the parser about how to display the values in the XML document. In order to give those instructions, you must create the style sheet as a document and save it. Then, to specify the accompanying style sheet of an XML file, after the declarative line, type a line as follows:

<?xml-stylesheet href="File Name or Path" type=""?>

This can also be written as follows:

<?xml-stylesheet type="" href="File Name or Path"?>

A style sheet is a formatting scheme that indicates to a Web browser how it should display the values of the elements in an XML document. The style sheet is created in a separate file that has the .css extension. Inside the document, you create sections that each specifies the necessary formatting based on its name.

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

Cascading Style Sheet

Previous Copyright © 2013-2022, FunctionX, Inc. Next