Introducing XML: Beginning XML Joe Fawcett, Liam R.E. Quin, and Danny Ayers John Wiley & Sons, Inc., 2012
Introducing XML: Beginning XML Joe Fawcett, Liam R.E. Quin, and Danny Ayers John Wiley & Sons, Inc., 2012
Chapter 1
Introducing XML
A binary file, at its simplest, is just a stream of bits (1s and 0s). binary
files can only be read and produced by certain computer programs
For example when saving a document in Microsoft Word, using a version
before 2003, the file created (which has a doc extension) is in a binary
format.
If you open the file in a text editor such as Notepad, you won’t be able to
see a picture of the original Word document (rubbish).
The characters in the document other than the actual text are metadata,
literally information about information.
Metadata can specify things such as which words should be shown in
bold, what text is to be displayed in a table, and so on.
To interpret this file you need the help of the application that created it.
Without the help of a converter, you won’t be able to open a MS word
document with another similar application such as WordPerfect.
The main advantage of binary formats is that they are concise and can be
expressed in a relatively small space.
<order>
<item code=‘BK123’>
<name>Care and Feeding of Wombats</name>
<price currency=‘USD’>42.00</price>
</item>
</order> - <order>
- <item code="BK123">
<name>Care and Feeding of Wombats</name>
<price currency="USD">42.00</price>
</item>
</order>
Dr. Khaled ALqawasmi, Zarqa University,
2013/2014
Beginning XML
Joe Fawcett, Liam R.E. Quin, and Danny Ayers
John Wiley & Sons, Inc., 2012
Chapter 2
Well-Formed XML
xmlns:hr=“http://wrox.com/namespaces/applications/hr/config“
http://www.cogsci.ed.ac.uk/~richard/xml-che
ck.html
<?xml version=”1.0”?>
<!DOCTYPE name [
<!ELEMENT name (first, middle, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>
<!ELEMENT last (#PCDATA)>
]>
<name>
<first>Joseph</first>
<middle>John</middle>
<last>Fawcett</last>
</name>
Syntax
<!ENTITY entity-name "entity-value">
DTD Example:
Syntax
<!ENTITY entity-name SYSTEM "URI/URL">
DTD Example:
XML example:
<author>&writer;©right;</author>
XML example:
<square width="100"></square>
or
<square width="100”/>
Dr. Khaled ALqawasmi, Zarqa University,
2013/2014
:Example 2
DTD example:
< !DOCTYPE family [
< !ELEMENT family (person)* >
< !ELEMENT person ( name ) >
< !ELEMENT name (#PCDATA) >
< !ATTLIST person id ID #REQUIRED
mother IDREF #IMPLIED
father IDREF #IMPLIED
children IDREFS #IMPLIED
]>
Dr. Khaled ALqawasmi, Zarqa University,
2013/2014
.Cont
XML example:
<family>
<person id = “jane” mother = “mary” father = “john”>
<name> Jane Doe </name>
</person>
<person id = “john” children = “jane jack”>
<name> John Doe </name>
</person>
<person id = “mary” children = “jane jack”>
<name> Mary Smith </name>
</person>
<person id = “jack” mother = “smith” father = “john”>
<name> Jack Smith </name>
</person>
</family>
Dr. Khaled ALqawasmi, Zarqa University,
2013/2014
DTD - Examples from the Net
http://www.xmlfiles.com/dtd/dtd_examples.as
p
Copied from http://www.vervet.com/
<!DOCTYPE NEWSPAPER [ <!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE, BYLINE, LEAD, BODY, NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)> <!ATTLIST ARTICLE AUTHOR CDATA
#REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">]>
Chapter 5
01 <xsd:simpleType name=‘MyInteger’>
02 <xsd:restriction base=‘xsd:integer’>
03 <xsd:minExclusive value=‘1234’/>
04 <xsd:maxInclusive value=‘5678’/>
05 </xsd:restriction>
06 </xsd:simpleType>
01 <xsd:simpleType name=‘MyInteger’>
02 <xsd:restriction base=‘xsd:integer’>
03 <xsd:minExclusive value=‘1234’/>
04 <xsd:maxInclusive value=‘5678’/>
05 </xsd:restriction>
06 </xsd:simpleType>
01 <xsd:simpleType name=‘MyInteger’>
02 <xsd:restriction base=‘xsd:integer’>
03 <xsd:minExclusive value=‘1234’/>
04 <xsd:maxInclusive value=‘5678’/>
05 </xsd:restriction>
06 </xsd:simpleType>
<import
namespace=””
schemaLocation=””>
/entry/body/p/born
If there was a whole book with lots of entries, and
you just wanted the one for John Armstrong, then
you would use this instead:
/book/entry[@id = “armstrong-john”]/body/p/born
Selected by Dr. Mohammed Al-Ghanim
Zarqa University, 2016/2017
XPath Node Types and Node Tests
So far you’ve seen XPath used only with
XML elements, attributes, and text nodes,
but XML documents can also contain node
types such as processing instructions and
comments. In addition, XPath 2 introduced
typed nodes: all the types defined by W3C
XML Schema are available.
/entry[@id = doc(“extra.xml”)//person/@id]/title