Escolar Documentos
Profissional Documentos
Cultura Documentos
1. Definition
2. Elements types
3. Well Formed XML document
4. Validate XML document
Definition
والـserver تحتوي على سجالت لنقلها على االنترنت بين الـtext files هدفها هو إعادة تنظيم هيكلية قواعد البيانات من اجل بناء ملفات نصيةXML لغة
smart phone application والهواتف الذكيةclient
XML is a documentation language used to re-organize the database and build text files with records in order to
send/receive them by internet between Client/Server and mobile application
Declaration Statement
Note:
version= “1.0” attribute is always 1.0 and must be written in the declaration statement
encoding and standalone are optional so they can used both or one of them or none of them
XML document must have one root example in the previous exercise the root is <Stock>
Elements Types
Examples:
The <Address> is a mixed content model, because it contains sub elements and text
Empty Content Model <Discount></Discount>
OR
<Discount />
Well Formed XML document
<P>
XML stands for <B>Extensible Markup <U>Language</B></U>
</P>
<P>
XML stands for <B>Extensible Markup <U>Language</U></B>
</P>
Names can start with letter or underscore, but cannot start with numbers or other punctuation characters
After the first character, numbers are allowed, as are the characters “-” and “.”
Names cannot contain spaces
Names cannot contain the “:” (unless used in namespace)
Names cannot start with the letters “xml” in uppercase, lowercase or mixed, so you cannot start a name with
“xml”, “XML”, “XmL” or any other combination
There cannot be a space after the opening “<” character, the name of the element must come after it. However
there can be a space before the closing “>” character if desired.
Example: < Price> خطأ
<Price > صح
The space is not allowed between /> i.e <Discount / > illegal خطأ <Discount /> صح
Do care to the sensitivity of the opening and closing elements
Comments are written as following:
<!-- This is a comment -->
Validate XML document
To validate the XML document content, we have to use other languages such as:
1. DTD (Document Type Definition)
2. Schema
Solution:
Internally
Products.xml
<?xml version=“1.0” encoding=“utf-8” standalone=“no” ?>
<!DOCTYPE Stock [
<!ELEMENT Stock (Product+)>
<!ELEMENT Product (Designation, Price, Qty, Discount?)>
<!ELEMENT Designation (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Qty (#PCDATA)>
<!ELEMENT Discount EMPTY>
]>
<Stock>
. . .
</Stock>
Externally
Products.dtd
<!ELEMENT Stock (Product+)>
<!ELEMENT Product (Designation, Price, Qty, Discount?)>
<!ELEMENT Designation (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Qty (#PCDATA)>
<!ELEMENT Discount EMPTY>
Products.xml
<?xml version=“1.0” encoding=“utf-8” standalone=“no” ?>
<!DOCTYPE Stock [SYSTEM “Products.dtd”]>
<Stock>
. . .
</Stock>
Conclusion:
Element Type Written in DTD
Simple Content Model <!ELEMENT Designation (#PCDATA)>
Example:
<Designation>Nido</Designation>
Element Content Model
Example1: Example1:
<College> <!ELEMENT College (Student+)>
<Student>Ahmad</Student> <!ELEMENT Student (#PCDATA)>
<Student>Raed</Student
</College>
Example2: Example2:
<College> <!ELEMENT College (Student, Teacher)+>
<Student>Mhd</Student> <!ELEMENT Student (#PCDATA)>
<Teacher>Salem</Teacher> <!ELEMENT Teacher (#PCDATA)>
<Student>Nancy</Student>
<Teacher>Rami</Teacher>
</College>
Example3: Example3:
<College> <!ELEMENT College (Student+, Teacher+)>
<Student>Abed</Student>
<Student>Israa</Student>
<Teacher>Raed</Teacher>
<Teacher>Diana</Teacher>
</College>
Note:
Comma (,) sequence خلف بعض
Example4:
<College>
<Student> | (OR) اوchoice
<FName>Rima</FName>
<Middle>Mhd</Middle> Cardinalities:
<LName>Intabli</LName> ? 0–1
</Student>
* 0–n
<Student>
<LName>Rifaii</LName> + 1-n
<Middle>Saleh</Middle>
<FName>Jamal</FName>
</Student>
<Student>Israa Sherkawi</Student>
</College>
Example4 Solution:
<!ELEMENT College (Student+)>
<!ELEMENT Student (#PCDATA)|((FName, Middle, LName)|(LName, Middle, FName))>
<Discount></Discount>
او
<Discount />
Mixed Content Model <!ELEMENT Address (#PCDATA | City |B)*>
<Address>
<City>Tripoli</City>
Tawjih Street
<B>CIS</B> Bldg
</Address>
How to validate attributes in DTD?
Example + syntax:
<College Phone=“01-820821”>
<Student ID=“100” Photo=“&Tar;”>Tarek Saad</Student>
<Student ID=“102” Photo=“&Rim;” Nationality=“Lebanese”>Rima Kouwatli</Student>
<Student ID=“103” Photo=“&Ah;”>Ahmad Rifaii</Student>
<Class Room=“303” Section=“2” Lang=“EN” />
<Class Room=“304” Section=“1” Lang=“FR” />
<Teacher Advisor= “100, 102”>Salam Naboulsi</Teacher>
<Book ISBN=“21-28b-33” Covers=“&co1; &co2;”>XML for Beginners</Book>
</College>
Note:
ID in student is an ID
Room attribute is an ID
Lang attribute could be “EN” or “FR”
Description
The data type of the attributes could be:
1. CDATA
2. NMTOKEN, NMTOKENS Text with multiple lines, feeding spaces
3. ID
4. IDREF, IDREFS
5. Enumeration
6. ENTITY, ENTITIES
Solution:
Note:
NDATA Not Parsed data which mean it is not text