0% found this document useful (0 votes)
5 views

C++ Debug

Uploaded by

lg.phones.0850
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

C++ Debug

Uploaded by

lg.phones.0850
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

HTML Forms

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>

5.7.18 Answer to Exercise 1


The following name/value pair will be sent to the CGI software. An ampersand (&) would precede or follow it
if other pairs were sent.

age=39

Two layout tips are worth remembering:

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.

5.7.19 Answer to Exercise 2


Your HTML code should look something like this:

What is your favourite movie?<BR>


<TEXTAREA NAME="movie-comments" COLS="50" ROWS="5"
WRAP=OFF></TEXTAREA>

5.7.20 Answer to Exercise 3


There may be conflicting requirements here. It is not easy to reflect the fact that the usual destination for
customers is within Egypt while promoting the others. For example, a scrolling list with Egypt at the top
would appear to satisfy this requirement, but the other countries would not be visible. Breaking
alphabetical ordering might distract some users:
HTML Forms

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

7.5.1 Default Namespaces


If no namespace is specified for an element, it is placed in the default namespace. An element's namespace (and the
namespace of all of its children) is defined with the special "xmlns" attribute on an element. Example:

<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

7.5.2 Explicit Namespaces


Multiple active namespaces can be defined using prefixes. Each namespace is declared with the attribute
"xmlns:ns", where ns is the prefix to be associated with the namespace. The containing element and its children may
then use this prefix to specify their membership to a namespace other than the default.

<uct xmlns="http://www.uct.ac.za" xmlns:dc="http://somedcns">


<dc:title>test XML document</dc:title>
</uct>

7.6 XML Schema


A XML Schema is an alternative to the DTD for specifying an XML document's structure and data types. It is capable of
expressing everything a DTD can, and more. Similar, alternative languages exist, such as RELAX and Schematron, but
XML Schemas are a W3C standard.

7.6.1 Schema Structure


Elements are defined using <element name="..." type="..." minOccurs="..." maxOccurs="...">, where:

• name refers to the tag.

• 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.

Example: <element name="title" type="string" minOccurs="1" maxOccurs="1"/>

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>

Note: Defaults for both minOccurs and maxOccurs are 1.


11
XML

7.6.3 Nested Elements


Instead of specifying an atomic type for an element, its type can be elaborated as a structure. This corresponds to
nested XML elements.

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

The content can be forced to conform to a regular expression:

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

7.6.6 Named Types


Types can be named and referred to at the top level of the XSD.

<element name="author" type="uct:authorType"/>


12
XML
<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>
</complexType>

7.6.7 Other Content Models


Instead of sequence, other content models may be used:

• choice means that only one of the children may appear.

• 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.

7.6.8 Schema Namespaces


Every schema should define a namespace for its elements and for internal references to types. For example:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.uct.ac.za"
xmlns:uct="http://www.uct.ac.za">

<element name="author" type="uct:authorType"/>

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

7.6.9 Schema Example


Here is an example of a full 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>

<element name="uct" type="uct:uctType"/>

</schema>

Here is a valid XML example for the above 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"
>

<title>test XML document</title>


<author email="[email protected]" office="410"
type="lecturer">Pat Pukram</author>
<version>
<number>1.0</number>
</version>
</uct>

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

7.7 Data and Metadata


Data refers to digital objects that contain useful information for information seekers. Metadata refers to descriptions of
these objects. Many systems manipulate metadata records, which contain pointers to the actual data.

7.7.1 Metadata Standards


To promote interoperability among systems, there are popular metadata standards to describe objects (both semantically
and syntactically).

• Dublin Core: uses fifteen simple elements to describe every object.

• MARC: a comprehensive system devised to describe items in a (physical) library.

• RFC1807: the computer science publications format.

• IMS Metadata Specification: courseware object description.

• VRA-Core: multimedia (especially image) description.

• EAD: aids to locate archived items.


Dublin Core Example
Dublin Core is one of the most popular (and simplest) metadata formats. It contains fifteen elements, each with
recommended semantics. All the elements are optional and repeatable. They are:

Title Creator Subject


Description Publisher Contributor
Date Type Format
Identifier Source Language
Relation Coverage Rights

Below is a Dublin Core in XML example:

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

7.7.2 Metadata Transformation


To do this, take the following steps:

1. Use an XML parser to parse data.


15
XML

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

my $parser = new DOMParser;


my $document = $parser->parsefile ('uct.xml')->getDocumentElement;
foreach my $title ($document->getElementsByTagName ('title'))
{
print "<title>".$title->getFirstChild->getData."</title>\n";
}
foreach my $author ($document->getElementsByTagName ('author'))
{
print "<creator>".$author->getFirstChild->getData."</creator>\n";
}
print "<publisher>UCT</publisher>\n";
foreach my $version ($document->getElementsByTagName ('version'))
{
foreach my $number ($version->getElementsByTagName ('number'))
{
print "<identifier>".
$number->getFirstChild->getData."</identifier>\n";

}
}

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:

uct/title uct/version/number uct/author/@office

7.8.1 XPath Syntax


• Expressions are separated by "/".

• 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.

• Symbols may be used for the possible axes:

Expression What it selects in current context


title "title" children
* All children
@office "office" attribute
author[1] First author node
/uct/title[last()] Last title within uct node at top level
of document
//author All author nodes that are descendant
from top level
. Context node
16
XML

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"/>

Selection and iteration examples:<if test="position()=last()">...</if> <choose>


<when test="$val=1">...</when> <otherwise>...</otherwise> </choose> <for-each
select="uct:number">...</for-each>

7.10.4 XSLT Example


<stylesheet version='1.0' xmlns='http://www.w3.org/1999/XSL/Transform'
xmlns:oaidc='http://www.openarchives.org/OAI/2.0/oai_dc/'
xmlns:dc='http://purl.org/dc/elements/1.1/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:uct='http://www.uct.ac.za'
>

<!--
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

You might also like