Friday, October 22, 2010
Week4 (2)
Today I did some research on Fuzzy Logic. I found that it is not simply ON or OFF (true/false) logic but can produce analogue/linear results/statements like "about right", "average", "too low" and "too high" called "linguistic synthesis". I found an example whereby the speed of a motor is controled by a Fuzzy Logig algorithm... very interesting stuff. Ordered a book called "Fuzzy Thinking: The New Science of Fuzzy Logic" by Bart Kosko.
Wednesday, October 20, 2010
Week4
Today we saw how to define and use ENTITY- represent some text, NOTATION-define a type, and NDATA-not parsable data (like images in xml), in DTDs. We also discussed some terms used in AI and Agent Technology. At home I attempted LAB4;
Quick questions:
CSS – Cascading Style Sheets – contains presentation & formatting instructions
Quick questions:
CMT3315 – Lab Session 04
1. What does XML stand for? And CSS ?
XML – eXtensible Markup Language – ie it can be extended by the user
2. Is this XML line well-formed? Say why.
<b><i>This text is bold and italic</b></i>
NO – the tags at the end are swapped
3. Is this XML document well-formed? Say why.
<?xml version= “1.0” ?>
<greeting>
Hello, world!
</greeting>
<greeting>
Hello Mars too!
</greeting>
NO – there is no Root Element
- - - - - - - - - - - - - - - - -
Longer questions:
1. Write an XML document that contains the following information: the name of this course. The name of this building. The name of this room. The start and end times of this session. Choose appropriate tags. Use attributes for the start and end times.
<? xml version=”1.0” ?>
<course start=”” end=””>
<name>CMT3315</name>
<building>Block C</building>
<room>402</room>
</course>
2. Have a look at the XML document below. Identify all the syntax errors.
<?xml version= “1.0” ?>
<!DOCTYPE bookStock SYSTEM "bookstock.dtd">
<bookstore>
<bookstore>
Doctype bookStock while root is bookstore
<book category="Cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<1stEdition>2005</1stEdition >
<2ndEdition>2007</2ndEdition >Cannot start tag with a number
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<1stEdition>2005</1stEdition >
<2ndEdition>2007</2ndEdition >Cannot start tag with a number
<price>19.99</price currency=”pounds sterling”>
cannot have an attribute in end tag
</book>
<book category="Children’>
</book>
<book category="Children’>
mismatch in qoutes
<title lang="en">Harry Potter and the enormous pile of money</title>
<title lang="en">Harry Potter and the enormous pile of money</title>
<!—best selling children’s book of the year --2009 -->
Invalid remark syntax
<author>J K. Rowling</author>
<1stEdition>2005</1stEdition>
<author>J K. Rowling</author>
<1stEdition>2005</1stEdition>
Cannot start tag with a number
<price>29.99</Price>
<price>29.99</Price>
Mismatch in case between tags
</book>
<book category="Web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<1stEdition>2003</1stEdition>
<2ndEdition >2008</2ndEdition >
</book>
<book category="Web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<1stEdition>2003</1stEdition>
<2ndEdition >2008</2ndEdition >
Cannot start tag with a number
<price>29.95</discount>
<price>29.95</discount>
<discount>15%</price>
Mismatch between tags
</book>
<book category="Computing">
<title lang=en>Insanely great – the life and times of Macintosh, the computer that changed everything </title>
</book>
<book category="Computing">
<title lang=en>Insanely great – the life and times of Macintosh, the computer that changed everything </title>
Value of attribute Should be in quotes
<author <!—other authors not listed -->>Steven Levy</author>
<author <!—other authors not listed -->>Steven Levy</author>
Invalid remark in opening tag
<1stEdition>1994</1stEdition>
<1stEdition>1994</1stEdition>
Cannot start tag with a number
<price>9.95</discount>
<price>9.95</discount>
<discount>15%</price>
Mismatch between tags
</book>No Closing Root tag
</book>No Closing Root tag
3. You are asked to produce a Document Type Declaration for a class of XML documents called “memo”. You come up with this .dtd file:
Your client says “That’s all very well, but every memo has to have a date. And some of them have to have a security classification too (you might want to write “Secret” at the top). And a memo has a serial number – I think that’s what you’d call an attribute, isn’t it?” How would you amend this .dtd file so that it did what the client wanted?
<!DOCTYPE memo
[
<!ELEMENT memo (security?,date,to,from,heading,body)>
[
<!ELEMENT memo (security?,date,to,from,heading,body)>
<!ELEMENT security (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ATTLIST memo serial CDATA #REQUIRED>
]>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ATTLIST memo serial CDATA #REQUIRED>
]>
Wednesday, October 13, 2010
Week3
Today we discussed DTD which is used to validate/check xml files. It can be either part of it (inside xml file) or in a sparate .dtd file with a reference from the xml file to it. We saw different types (eg. CDATA etc), and the cardinality & optionality as in;
teacher 1 and only 1 (unary)
course+ 1 or more (1..n)
assistant* 0 or more (0..n)
location? 0 or 1 (optional - boolean)
We also saw #IMPLIED (optional), #REQUIRED (NOT optional) & #FIXED (constant)
We also mentioned attributes and their types;
CDATA – ENTITY – ENTITIES – ID – IDREF – IDREFS – NMTOKEN – NMTOKENS
We also mentioned LaTeX scripting, AL & Intelligent Agents, and web services (UDDI, WSDL & SOAP)
CMT3315 – Lab Session 03
Then I did the lab3 exercises:
<!-- a comment -->
<student dob="03/06/1960">
<name>Tony Montanaro</name>
<email>tonimonti@gmail.com</email>
<studentNumber>M00310803</studentNumber>
<homeTown>Mosta</homeTown>
</student>
<Label>Common Names:</label>
All tags mismatch on case
<2ndCity cityNum=”2”>
Cannot start a tag with a number
<BorderingBodyOfWater <!--Also Lake Victoria --> >
Invalid remark in opening tag
<MajorCity cityNum=’6’ cityNum=’7’>
Duplicate attribute name in same tag
teacher 1 and only 1 (unary)
course+ 1 or more (1..n)
assistant* 0 or more (0..n)
location? 0 or 1 (optional - boolean)
We also saw #IMPLIED (optional), #REQUIRED (NOT optional) & #FIXED (constant)
We also mentioned attributes and their types;
CDATA – ENTITY – ENTITIES – ID – IDREF – IDREFS – NMTOKEN – NMTOKENS
We also mentioned LaTeX scripting, AL & Intelligent Agents, and web services (UDDI, WSDL & SOAP)
CMT3315 – Lab Session 03
Then I did the lab3 exercises:
- Write an XML document that contains the following information: your name. Your email address. Your student number. Your home town. Your date of birth. Choose appropriate tags. Use Attributes for the date of birth.
ANS:
<?xml version="1.0" encoding="UTF-8"?><!-- a comment -->
<student dob="03/06/1960">
<name>Tony Montanaro</name>
<email>tonimonti@gmail.com</email>
<studentNumber>M00310803</studentNumber>
<homeTown>Mosta</homeTown>
</student>
2. Have a look at the XML document below. Identify all the syntax errors.
ANS:
<!DOCTYPE countryCollection SYSTEM "countryList.dtd">
<CountryList>
Doctype declaration does not match root element<!--Data from CIA --Year Book -->
Invalid characters in remarks<Label>Common Names:</label>
All tags mismatch on case
<2ndCity cityNum=”2”>
Cannot start a tag with a number
<Capital>Tokyo </capital cityNum=”1”>
Invalid attribute in END tag<BorderingBodyOfWater <!--Also Lake Victoria --> >
Invalid remark in opening tag
<MajorCity cityNum=’6’ cityNum=’7’>
Duplicate attribute name in same tag
</country>
Missing </CountryList> closing tag
Note that many errors repeat many times.
Wednesday, October 6, 2010
Week2
Today we saw more XML syntax, prolog, onthology, declarations and purpose. We saw how an xml file can be well-formed, and the use of parsers in applications,
3. Assume that (with suitable changes) all these documents could become XML documents. Imagine, and describe, applications that could use these documents.
CMT3315 – Lab Session 02
1. Have a look at the documents below. Some are XML documents, some are HTML documents, some may be neither. See if you can decide which are which.
ANS:
1-HTML, 2-XML, 3-HTML, 4-none (close to XML), 5-none, 6-none (close to XML), 7-HTML with JavaScript
2. Make a list of the distinctive characteristics of an XML document, in terms of things that you can spot when looking at the code.
ANS:
- There is an XML decleration at the top (<?xml version= “1.0” ?>)
- It must have a DOCTYPE declaration
- There is only one root element
- Each opening tag has an exact matching, corresponding closing tag
- Tags cannot be cross nested but yes can be nested
- XML is case sensitive
3. Assume that (with suitable changes) all these documents could become XML documents. Imagine, and describe, applications that could use these documents.
NB I’ve removed one or more lines from each document to stop it being too easy.
ANS:
- A web browser - it could display the values between opening and closing tags but not the tags themself
- Using XSLT some documents can be formated and displayed on a web browser
- Some XML files can be used as a data store (like a flat database file)
- Can be used to transmit data between machines and/or applications
Monday, October 4, 2010
Converting data to xml
In the weekend I tried a small php prog to convert MySql data to xml. Each field (column) name is created as a tag while each field value is put between these tags. First a connection and a query are run against a small table which has users' id, name and password (3 columns).
initDB(); // opens and connects to Test db
$table_id = 'user';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query);
Then a document object with the root element (testroot) is created;
$doc = new DOMDocument('1.0', 'UTF-8');
$root = $doc->createElement('testroot');
$root = $doc->appendChild($root);
Then for each record (row) in the table the table name is used as an element under the root. For testing I added two attributes to this element;
while($row = mysql_fetch_assoc($dbresult)) {
$occ = $doc->createElement($table_id);
$occ = $root->appendChild($occ);
$occ->setAttribute('att1', 'val1');
$occ->setAttribute('att2', 'val2');
Then for each field (column) in the row ($row array) each name/value pair are added as elements (tags) and values (between the tags);
foreach ($row as $fName => $fVal) {
$child = $doc->createElement($fName);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fVal);
$value = $child->appendChild($value);
} // foreach
} // while
The doc object is then put into an xml string, saved as an xml file (TestTony.xml) and displayed on screen;
$xml_string = $doc->saveXML();
$doc->save("TestTony.xml");
echo $xml_string;
Note that in IE8 the tags can only be seen if viewsource is used. However if you open the xml file you see this;
<?xml version="1.0" encoding="UTF-8" ?>
initDB(); // opens and connects to Test db
$table_id = 'user';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query);
Then a document object with the root element (testroot) is created;
$doc = new DOMDocument('1.0', 'UTF-8');
$root = $doc->createElement('testroot');
$root = $doc->appendChild($root);
Then for each record (row) in the table the table name is used as an element under the root. For testing I added two attributes to this element;
while($row = mysql_fetch_assoc($dbresult)) {
$occ = $doc->createElement($table_id);
$occ = $root->appendChild($occ);
$occ->setAttribute('att1', 'val1');
$occ->setAttribute('att2', 'val2');
Then for each field (column) in the row ($row array) each name/value pair are added as elements (tags) and values (between the tags);
foreach ($row as $fName => $fVal) {
$child = $doc->createElement($fName);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fVal);
$value = $child->appendChild($value);
} // foreach
} // while
The doc object is then put into an xml string, saved as an xml file (TestTony.xml) and displayed on screen;
$xml_string = $doc->saveXML();
$doc->save("TestTony.xml");
echo $xml_string;
Note that in IE8 the tags can only be seen if viewsource is used. However if you open the xml file you see this;
<?xml version="1.0" encoding="UTF-8" ?>
<testroot>
<user att1="val1" att2="val2">
<id>TM</id>
<name>Tony Montanaro</name>
<password>1234</password>
</user>
<user att1="val1" att2="val2">
<id>TT</id>
<name>Test User</name>
<password>*A4B6157319038724E3560894F7F932C8886EBFCF</password>
</user>
<user att1="val1" att2="val2">
<id>TO</id>
<name>Tony</name>
<password>1234</password>
</user>
<user att1="val1" att2="val2">
<id>MM</id>
<name>Mario</name>
<password>4567</password>
</user>
<user att1="val1" att2="val2">
<id>VIC</id>
<name>Victor</name>
<password>VCC</password>
</user>
<user att1="val1" att2="val2">
<id>JOE</id>
<name>Joe</name>
<password>JJJ</password>
</user>
<user att1="val1" att2="val2">
<id>CCC</id>
<name>Carmen</name>
<password>CCC</password>
</user>
</testroot>
Saturday, October 2, 2010
Notes Revision & Qs
Today I revised some class notes and module handbook. I looked up a few items I read like;
- How HTML & XML eveolved from SGML
- What is Semantic Web? - A Web in which computers become capable of analyzing all the data on the Web – the content, links, and transactions between people and computers. (ref: 02/10/2010 - http://en.wikipedia.org/wiki/Semantic_Web)
- AJAX (Asynchronous JavaScript and XML) - a group of technologies combined; HTML, CSS, DOM, JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads. (ref: 02/10/2010 - http://en.wikipedia.org/wiki/Ajax_(programming))
- What was the first Browser to read XML?
- What is the current status of CSS? - CSS3
- What is the current status of XSL? - ver 2.0
- What are the relative merits of
CSS and XSL? - CSS for formating/layaout (presentation) of HTML while XSL to transform/format xml. - What are the implications of the concept of the document tree? - a hierarchical representation of data structures and relations
Subscribe to:
Posts (Atom)