C++ Debug
C++ Debug
Choose a processor:<BR>
<SELECT name="processor" SIZE=4>
<OPTION>Motorola 68000</OPTION>
<OPTION>Intel 8088</OPTION>
<OPTION>Intel Pentium MMX</OPTION>
<OPTION>Intel Pentium II</OPTION>
<OPTION>Intel Pentium III</OPTION>
<OPTION>Intel Celeron</OPTION>
<OPTION>PowerPC G3</OPTION>
<OPTION>PowerPC G4</OPTION>
<OPTION>AMD Athlon</OPTION></SELECT>
age=39
1. Use tables to layout the form in an organised way (see Unit 4).
2. You can use the <BR> tag (no closing tag needed) to move text or form objects to the
next line. You can use the <P></P> tags to space your work in paragraphs.
Destination Country:<BR>
<SELECT NAME="colour" SIZE="3" MULTIPLE>
<OPTION>Egypt</OPTION>
<OPTION>Bahrain</OPTION>
<OPTION>Kuwait</OPTION>
<OPTION>Lebanon</OPTION>
<OPTION>Oman</OPTION>
</SELECT>
Alternatively, you could use alphabetical ordering to force the user to scroll through at least the options that
precede the most likely destination, Egypt. But there would only be one option before Egypt, so it could
be moved to last. To help users find Egypt, it can be pre-selected:
Destination Country:<BR>
<SELECT NAME="colour" SIZE="3" MULTIPLE>
<OPTION>Bahrain</OPTION>
<OPTION>Kuwait</OPTION>
<OPTION>Lebanon</OPTION>
<OPTION>Oman</OPTION>
<OPTION SELECTED>Egypt</OPTION>
</SELECT>
The final alternative is to use a menu button: it can preserve alphabetic ordering and shows all the other
options:
HTML Forms
Destination Country:<BR>
<SELECT NAME="colour">
<OPTION>Bahrain</OPTION>
<OPTION>Egypt</OPTION>
<OPTION>Kuwait</OPTION>
<OPTION>Lebanon</OPTION>
<OPTION>Oman</OPTION>
</SELECT>
Note that, when using a menu button, you should not pre-select Egypt if you want customers for internal
flights to see the other options. Pre-selecting does exactly that: it would leave only Egypt visible on the button
and most customers would not click on the button to reveal the other options in the menu.
XML
<uct xmlns="http://www.uct.ac.za">
Namespaces are specified using URIs, thus maintaining uniqueness. Universal Resource Locator (URL) =
location-specific
Universal Resource Name (URN) = location-independent Universal Resource Identifier (URI) = generic
identifier
• type can be custom-defined or one of the standard types. Common predefined types include string,
integer and anyURI.
• minOccurs and maxOccurs specify how many occurrences of the element may appear in an XML
document. unbounded is used to specify no upper limits.
7.6.2 Sequences
Sequences of elements are defined using a complexType container:
<complexType>
<sequence>
<element name="title" type="string"/>
<element name="author" type="string" maxOccurs="unbounded"/>
</sequence>
</complexType>
<element name="uct">
<complexType>
<sequence>
<element name="title" type="string"/>
<element name="author" type="string" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
7.6.4 Extensions
Extensions are used to place additional restrictions on an element's content. For instance, the content can be restricted to
be a value from a given set:
<element name="version">
<simpleType>
<restriction base="string">\
<enumeration value="1.0"/>
<enumeration value="2.0"/>
</restriction>
</simpleType>
</element>
<element name="version">
<simpleType>
<restriction base="string">
<pattern value="[1-9]\.[0-9]+"/>
</restriction>
</simpleType>
</element>
7.6.5 Attributes
Attributes can be defined as part of complexType declarations.
<element name="author">
<complexType>
<simpleContent>
<extension base="string">
<attribute name="email" type="string" use="required"/>
<attribute name="office" type="integer" use="required"/>
<attribute name="type" type="string"/>
</extension>
</simpleContent>
</complexType>
</element>
• all means that each child may appear or not, but at most once each.
Consult the specification for more detail on these and other content models.
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.uct.ac.za"
xmlns:uct="http://www.uct.ac.za">
<complexType name="authorType">
<simpleContent>
<extension base="string">
<attribute name="email" type="string" use="required"/>
<attribute name="office" type="number" use="required"/>
<attribute name="type" type="string"/>
</extension>
</simpleContent>
</complexType>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.uct.ac.za"
xmlns:uct="http://www.uct.ac.za" elementFormDefault="qualified"
attributeFormDefault="unqualified"
>
<complexType name="authorType">
<simpleContent>
<extension base="string">
<attribute name="email" type="string" use="required"/>
<attribute name="office" type="integer" use="required"/>
<attribute name="type" type="string"/>
</extension>
</simpleContent>
13
XML
</complexType>
<complexType name="versionType">
<sequence>
<element name="number">
<simpleType>
<restriction base="string">
<pattern value="[1-9]\.[0-9]+"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
<complexType name="uctType">
<sequence>
<element name="title" type="string"/>
<element name="author" type="uct:authorType"/>
<element name="version" type="uct:versionType"/>
</sequence
</complexType>
</schema>
<uct xmlns="http://www.uct.ac.za"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.uct.ac.za
http://www.husseinsspace/teaching/uct/2003/csc400dl/uct.xsd"
>
Activity 2: Schema
Write a Schema for the following XML document.
<article xmlns="http://article.com">
<name>Fermat's Last Theorem</name>
<date>20010112</date>
<length unit="pages">11</length>
<author>
<first>Jonathan</first>
<last>Smith</last>
</author>
<author>
<first>Mary</first>
<last>Carter</last>
</author>
</article>
14
XML
<oaidc:dc xmlns="http://purl.org/dc/elements/1.1/"
xmlns:oaidc="http://www.open
<title>02uct1</title>
<creator>Hussein Suleman</creator>
<subject>Visit to UCT </subject>
<description>the view that greets you as you emerge from the tunnel
under th
<publisher>Hussein Suleman</publisher>
<date>2002-11-27</date>
<type>image</type>
<format>image/jpeg</format>
<identifier>http://www.husseinsspace.com/pictures/200230uct/02uct1.j
pg
</identifier>
<language>en-us</language>
<relation>http://www.husseinsspace.com</relation>
<rights>unrestricted</rights>
</oaidc:dc>
2. Use SAX/DOM to extract individual elements and generate the new format.
The following code converts UCT to Dublin Core (Don't worry if you do not understand it):
}
}
As you will see later in this unit, there is an easier way to achieve this in the unit.
7.8 XPath
The XML Path Language (XPath) supplies a mechanism to address particular nodes or sets of nodes in an XML document.
XPath expressions can be used to write precise expressions to select nodes without using procedural DOM statements. For
example, we can address particular nodes using expressions like:
• In general, each subexpression matches one or more nodes in the DOM tree.
• Each sub-expression has the form: axis::node[condition1][condition2]... where axis can be used to select
children, parents, descendants, siblings, and so on.
text is replaced by the textual content. Plain text is usually sufficient. For example:
<text>1.0</text> 1.0
element is replaced by an XML element with the indicated tag. Usually the actual tag can be used. Example:<element
name="dc:publisher">UCT</element> <dc:publisher>UCT</dc:publisher>
apply-templates explicitly applies templates to the specified nodes. Example: apply-templates select="uct:version"/>
call-template calls a template in a similar way to calling a function. This template may have parameters and
must have a name attribute instead of a match. Example:<call-template name="doheader"> <with-param
name="lines">5</with-param> </call-template> <template name="doheader"> <param name="lines">2</param> ...
</template>
variable sets a local variable. In XPath expressions, a $ prefix indicates a variable or parameter instead of a node.
Example:<variable name="institution">UCT</variable> <value-of select="$institution"/>
<!--
UCT to DC transformation Hussein Suleman
v1.0 : 24 July 2003
-->
<output method="xml"/>
<variable name="institution"><text>UCT</text></variable>
<template match="uct:uct">
<oaidc:dc
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0
/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title><value-of select="uct:title"/></dc:title>
<apply-templates select="uct:author"/>
<element name="dc:publisher">
<value-of select="$institution"/>
</element>
<apply-templates select="uct:version"/>
</oaidc:dc>
</template>
<template match="uct:author">
<dc:creator>
<value-of select="."/>
</dc:creator>
</template>
<template match="uct:version">
<dc:identifier>
18
XML
<value-of select="uct:number"/>
</dc:identifier>
</template>
</stylesheet>
This is not the simplest XSLT that solves the problem. The transformed XML looks like this:
<?xml version="1.0"?>
<oaidc:dc xmlns:oaidc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:uct="http://www.uct.ac.za"
xsi:schemaLocation=
"http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>test XML document</dc:title>
<dc:creator>Pat Pukram</dc:creator>
<dc:publisher
xmlns:dc="http://purl.org/dc/elements/1.1/">UCT</dc:publisher>
<dc:identifier>1.0</dc:identifier>
</oaidc:dc>
7.11 Answers
7.11.1 Answer to Activity 1
One possible DTD is:
<!DOCTYPE id_data [
<!ELEMENT id_data (name, date_of_birth, blood_group?)>
<!ELEMENT name (firstname, middlename*, lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT middlename (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ATTLIST date_of_birth day CDATA #REQUIRED>
<!ATTLIST date_of_birth month CDATA #REQUIRED>
<!ATTLIST date_of_birth year CDATA #REQUIRED>
<!ELEMENT blood_group (#PCDATA)>
]>
19