Title: XML By Example, Second Edition, Benoit Marchal, 2002, Que Books: Excerpts for EPA Webmasters
1XML By Example, Second Edition, Benoit Marchal,
2002, Que Books Excerpts for EPA Webmasters
- Brand Niemann
- XML Web Services Evangelist
- Data Standards Branch
- December 28, 2001
Disclaimer Any reference to or depiction of the
commercial product of any vendor is for
illustrative purposes only and does not
constitute an endorsement by EPA or the trainer.
2Overview
- Introduction
- Introduction.
- XML Galaxy Chapter 1.
- Book Organization
- XML Syntax (DTDs, schemas, and Namespaces)
Chapters 2-4. - Style sheets Chapters 5 and 6.
- Manipulate XML Documents Chapters 7-9.
- Create Models for XML Documents Chapter 10.
- Realistic e-Commerce Application Chapter 11-12.
- Crash Course in Java-Appendix A.
- DTD and XML Schema Simplified Types-Appendix B.
3Introduction
- Philosophy The best way to teach computer
programming is by using multiple examples. - Who should use this book
- HTML whiz move to the next level.
- Publish large or dynamic document base XML can
simplify your work. - Web developer XML enables you to do cool
things. - E-Commerce of EDI XML has lots to offer.
- Use software that supports XML understand how
to make the best use of it.
4Introduction
- Two classes of applications
- Publishing.
- Data exchange (application integration).
- Requisites
- Basic HTML coding.
- Read and understand simple JavaScript
- Some Java (See Appendix A. Crash Course on Java).
- Code examples and additional materials
- http//www.quepublishing.com/series/by_example/
- http//www.marchal.com
5Chapter 1. XML Galaxy
- Essential concepts
- Which problems XML solves (what XML is good at).
- What a markup language is and what the
relationship between XML, HTML, and SGML is. - How and why XML was developed.
- Typical applications of XML, with examples.
- The benefits of using XML when compared to HTML.
When is XML better than HTML?
6Chapter 1. XML Galaxy
- Contents
- Introduction
- Document Structure
- Markup Language History
- Applications
- Companion Standards
- Software Tools
- Code Listings
7Chapter 1. XML Galaxy
- Introduction
- XML stands for eXtensible Markup Language.
- Developed by the World Wide Web Consortium (W3C)
to overcome the limitations in HTML. - With almost 100 tags, it is not uncommon to see
Web pages that have more markup than content. - By 2002, 75 of surfers wont be using a PC.
- Smaller, faster, and lighter browsers and no
predefined tags, but structure. - XML will not replace HTML but HTML will converge
towards XML through the XHTML standard (rewrite
the HTML standard in XML).
8Chapter 1. XML Galaxy
- Introduction
- XMLs role in the near-term
- Large web site maintenance.
- Exchange between organizations.
- Offloading and reloading of databases.
- Syndicating of content (e.g. Wall Street
Journal). - Electronic commerce (collaboration to serve
customers). - Scientific applications.
- Electronic books.
- Handheld devices and smartphones.
9Chapter 1. XML Galaxy
- Open Listing 1.1 memo.txt.
- Document Structure
- A title
- A header made of
- The sender
- The recipient
- A subject
- A body text made of
- Three paragraphs
- Several URLs
- A signature
10Chapter 1. XML Galaxy
- Markup Language History
- Every electronic document uses some kind of
markup. - Progression from procedural markup to generalized
markup through generic coding. - Procedural (for some output device) Listing 1.2
- Three problems (1) structure not recorded (2)
inflexible and (3) inherently slow process. - Generic coding Listing 1.3
- Two benefits over procedural (1) higher
portability and flexibility and (2) closer to
describing the structure.
11Chapter 1. XML Galaxy
- Markup Language History (continued)
- Progression from procedural markup to generalized
markup through generic coding. - Standard Generalized Markup Language (SGML)
Listing 1.4. - Advantages (1) an international standard (2)
markup conforms to a model that can be processed
by software or stored in a database (3) author
can both markup document and describe its
structure (DTD-Document Type Definition) and (4)
a language to describe documents. - Famous examples (1) HTML is an SGML DTD (2)
used by Department of Defense to promote
electronic document exchange and (3) used in
DocBook for technical books and articles. - Disadvantages (1) too complex to apply on the
Web and (2) costly to implement in general.
12Chapter 1. XML Galaxy
- Markup Language History (continued)
- Progression from procedural markup to generalized
markup through generic coding. - Hypertext Markup Language (HTML) Listing 1.5,
1.6, and 1.7. - Advantages (1) an easy to use application of
SGML that does not enforce structure and (2) the
set of tags is adapted to the structure of
hypertext documents. - Disadvantages (1) has very few options for
organizing data and (2) evolved to include many
formatting tags so now partly a procedural markup
language! - Contradiction tags are used to express not only
structure, but presentation!
13Chapter 1. XML Galaxy
- Markup Language History (continued)
- Progression from procedural markup to generalized
markup through generic coding. - eXtensible Markup Language (XML) Listing 1.8.
- The evolution of Web site publishing
- The first 20 pages are produced with enthusiasm.
- Somebody wants to change the appearance.
- Someone changes the appearance manually.
- Another 50 pages are added with enthusiasm.
- Somebody wants to change the appearance, but
doesnt want to do it manually. - XML solves this problem by separating content
from appearance and managing content better than
in HTML.
14Chapter 1. XML Galaxy
- Applications
- Two basic types
- Documents for human consumption.
- Document publishing to multiple formats and
audiences. - HTML for the Web.
- PDF for reading and printing.
- WML (wireless Markup Language) for portable
devices and the visually handicapped. - Data for software consumption.
- Exchange of data (the application as the XML
document). - Both documents and databases can be expressed in
the XML document hierarchical (tree-like)
structure. - Listing 1.9.
15Chapter 1. XML Galaxy
- Companion Standards (not comprehensive)
- XML Namespaces
- Second to none in importance.
- Makes it possible to use the same element names
in different XML applications with no conflict
when brought together. - Listing 1.10.
- Style Sheets
- Probably the mostly widely discussed.
- Two types (1) XSL (XML Stylesheet Language) and
(2) CSS (Cascading Style Sheets) to control
rendering on screen, on paper, or in an editor. - XSL is more powerful, but CSS is widely
implemented. - Listing 1.11.
16Chapter 1. XML Galaxy
- Companion Standards (not comprehensive)
- DOM (Document Object Model) and SAX (Simple API
for XML) - Allow applications to read XML documents.
- Complimentary DOM is best suited for browsers
and editors and SAX is best suited for all the
rest. - XLink and XPointer
- Two parts of one standard currently under
development. - Provides a mechanism to establish relationships
between documents - Listing 1.12.
17Chapter 1. XML Galaxy
- Software Tools (do more in other training units)
- XML Browsers
- Microsoft Internet Explorer 5 and 6.
- Netscape 6 (but not XSL).
- W3C Amaya (and editor).
- XML Editors
- XML Spy 4.2 (programmers, but Document Editor
now) - XMetal (clerical staff)
- XML Parsers
- Apaches Xerces
- XSL Processor
- Apaches Xalan
18Chapter 1. XML Galaxy
- Code listings
- Page 11 - 1.1 memo.txt
- Page 16 - 1.2 memo.rft
- Page 18 - 1.3 memo.tex
- Page 20 - 1.4 memo.sgml
- Page 21 - 1.5 memo.html
- Page 22 - 1.6 memocss.html
- Page 24 - 1.7 memocss2.html
- Page 27 - 1.8 memo.xml
- Page 31 - 1.9 A List of Products in XML (not in
folder) - Page 33 - 1.10 list.xml
- Page 34 - 1.11 basic.xsl
- Page 35 - 1.12 resources.xml
- Also error.txt and memo.tbr
19Review
- Book Organization
- XML Syntax (DTDs, schemas, and Namespaces)
Chapters 2-4. - Style sheets (XSL) Chapters 5 and 6.
- Manipulate XML Documents Chapters 7-9.
- Create Models for XML Documents Chapter 10.
- Realistic e-Commerce Application Chapter 11-12.
- Crash Course in Java-Appendix A.
- DTD and XML Schema Simplified Types-Appendix B.
20Chapter 2. XML Syntax
- This chapter
- How to write and read XML documents.
- How XML structures documents.
- How and where XML can be used.
21Chapter 2. XML Syntax
- Contents
- Basics
- Advanced
- FAQs
- Four Common Errors
- Two Applications
- XML Editors
- Coding Listings
22Chapter 2. XML Syntax
- Basics
- Markup differentiates XML from plain text to make
it more readable to humans and software - See Listings 2.1 and 2.2.
- XML has strict syntax rules
- See next slide.
- XML elements have some popular conventions
- Entirely in lowercase with multiple words
separated by a hyphen. - Capitalize the first letter of each word with no
separation between multiple words (camel case). - Try to be consistent. See Listing 2.3 of poor
style.
23Chapter 2. XML Syntax
- Basics
- Some XML syntax rules
- Unlike HTML, both start and end tags are
required. - Names must begin with either a letter or the
underscore character (_). Spaces are not
allowed. Names cannot start with the string xml
which is reserved for the XML specification
itself. - Elements can have attributes. Attributes have a
name and a value. The names follow the same rules
as element names. - Elements can be empty (no content) noted as
. - The name of the attribute is separated from the
value by the equal character and the value is
enclosed in single or double quotation marks. - The XML declaration is the first line of the
document, there is one and only one root of the
XML document, and all elements are nested in a
hierarchical tree.
24Chapter 2. XML Syntax
- Advanced
- Comments (for documentation) must be outside the
markup -
- Unicode (major extension to the ASCII character
set to support all spoken languages) -
- Entities (complex topic)
- us United
States - Processing instructions (non-XML statements such
as scripts - typetext/xsl?
- Special attributes (xml space and xml lang).
- CDATA (character data)
- John
Doe
25Chapter 2. XML Syntax
- FAQs
- Code indenting
- Makes the code more readable and is generally
ignored by the parser. If whitespace is important
then use xmlspace. - End tag
- The browser can be programmed to deduce it but
the parser doesnt know how to interpret it. - See Listing 2.4.
- XML and semantic
- XML alone does not define the meaning of the
document but the application does along with some
XML companion standards. - See Listing 2.5.
26Chapter 2. XML Syntax
- Four Common Errors
- 1. Forgetting end tags
- End tags are mandatory except for empty elements.
- 2. Forgetting that XML is case sensitive
- 513-744-7098 is wrong.
- 3. Introducing spaces in the name of the element
- The XML parser interprets spaces as the beginning
of an attribute. - 4. Forgetting the quotes for the attribute value
- 513-744-8889 in wrong.
27Chapter 2. XML Syntax
- Two applications
- Publishing (XML roots)
- Advantages
- Convert XML documents to different media (Web,
print, etc.) - Ability to enforce common structure that
simplifies editing for large document sets. - Future proofs information because structure is
more stable than formatting. - Listing 2.6 is for a monthly newsletter.
28Chapter 2. XML Syntax
- Two applications (continued)
- Electronic commerce
- Advantages
- HTML, which is ideal for storefronts, is
inadequate for business-to-business e-commerce. - If the e-commerce documents are written in XML,
the markup matches the structure of the document. - The focus is not merely on reducing costs but
increasingly on opening new markets. - Listing 2.7 is for a book order.
29Chapter 2. XML Syntax
- XML Editors
- Can do much better than using a simple text
editor. - XML Spy for developers (Document editor now).
- XMetal for editors.
- XML Notepad from Microsoft (1998).
- XML Pro (http//www.vervet.com)
- Morphon (http//www.morphon.com)
- Epic from Arbortext (http//www.arbortext.com)
30Chapter 2. XML Syntax
- Code listings
- Page 42 2.1 abook.xml
- Page 43 2.2 abook.txt
- Page 46 2.3 poorstyle.xml
- Page 58 2.4 abook.html
- Page 59 2.5 mixedup.xml
- Page 62 2.6 excerpt.xml
- Page 64 2.7 order.xml
31Chapter 3. XML Namespaces
- This chapter
- How namespaces compliment XML extensibility.
- How to use namespaces in documents.
- How the W3C uses namespaces in its own
recommendations.
32Chapter 3. XML Namespaces
- Contents
- The Problem
- Namespaces
- URIs
- Scoping
- Digital Signatures Example
- Code Listings
33Chapter 3. XML Namespaces
- The Problem
- In a networked environment, such as the Web,
extensibility must be managed to avoid conflicts. - Namespaces places the name of XML elements in a
more global context. - Example
- You publish your bookmarks see Listing 3.1.
- Someone else rates the quality of your bookmarks
by adding a new element See Listing 3.2. - Someone else rates the quality of your bookmarks
using the same element, but against family
criteria See Listing 3.3. - Someone then tries to combine the two ratings in
an incompatible way See Listing 3.4. - Someone realizes that different element names are
needed for each concept See Listing 3.5.
34Chapter 3. XML Namespaces
- Namespaces
- Two basic solutions
- Establish a global registry of tags names in use.
- Introduce a flexible and friendly mechanism to
manage the extensibility (anyone can still make
up their tag names). - Examples
- Listing 3.6 equivalent to Listing 3.5 but with
namespaces (prefixes are declared with URIs). - Listing 3.7 with different prefixes, but with the
same namespace (URI).
35Chapter 3. XML Namespaces
- URIs
- Uniform Resource Identifier.
- In most cases are URLs (Uniform Resource
Locator), but URNs (Universal Resources Names)
are also acceptable. - URLs are guaranteed to be unique because they are
based on domain names, which are registered to
prevent conflicts. - It need not be valid (it might not point to
anything). - They best URLs strike a balance between brevity
and descriptiveness. - To guarantee uniqueness, register your own domain
name.
36Chapter 3. XML Namespaces
- Scoping
- The namespace is valid for the element where it
is declared and all the elements within its
content. - Examples
- Listing 3.8 shows three namespaces declared (bk
declared on the top-level element and valid for
all elements and ns is declared twice for the two
rating elements but with different URIs). - Listing 3.9 shows that attributes can be
associated with a namespace.
37Chapter 3. XML Namespaces
- Digital Signatures Example
- Namespaces make it possible to develop reusable
elements, elements that can be used in multiple
XML documents. - Listing 3.10 is an example of a signed XML
document with the digital signature at the top
and the data at the bottom, each with its own
namespace. - The W3C and IETF have developed standards for
signing documents to warrant that the document
has not been tampered with.
38Chapter 3. XML Namespaces
- Code listings
- Page 72 3.1 resources.xml
- Page 73 3.2 ratings.xml
- Page 73 3.3 pgratings.xml
- Page 74 3.4 combinedratings.xml
- Page 75 3.5 prefixratings.xml
- Page 76 3.6 nsratings.xml
- Page 78 3.7 2prefixes.xml
- Page 82 3.8 scooping.xml
- Page 83 3.9 sponsored.xml
- Page 85 3.10 signed.xml
- Also straratings.xml and temp.xml
39Chapter 4. XML Models
- This chapter
- Model XML documents.
- Express these models in DTDs or XML Schemas.
- Validate documents against the model.
40Chapter 4. XML Models
- Contents
- DTDs and XML Schemas
- The DTD Syntax
- Relationship Between the DTD and the Document
- Advanced DTD Concepts
- The Schema Syntax
- Namespaces and Other Advanced Schema Concepts
- Modeling XML Documents
- Modeling Documents from an Object Model
- Modeling from Scratch
- A Tool to Help
41Chapter 4. XML Models
- DTDs and XML Schemas
- Serve the same objective describe document
structure and valid against model. - DTD is a proven SGML solution, but is not
perfect. - Lack support for object-oriented modeling.
- Ill-suited to data exchange and application
integration. - Have their own, non-XML syntax.
- XML Schemas solve these deficiencies but at the
price of increased complexity.
42Chapter 4. XML Models
- The DTD Syntax
- The Document Type Declaration
- See Listing 4.1 (declares root element of the
document and the filename). - Not the Document Type Definition (DTD).
- The DTD Itself
- See Listing 4.2 (a special syntax to declare
every object-elements, attributes, and so on). - Skim read pages 92-96.
43Chapter 4. XML Models
- Relationship Between the DTD and the Document
- Specifies which elements are allowed in the
document. - Exercise Validate Listing 4.1 with Listing 4.2
in XML Spy 4.2. - Exercise Understand why Listings 4.3 and 4.4 are
valid and invalid, respectively. - DTDs make all the writers follow the same set of
editorial rules and can enforce the structure of
XML documents in an enterprise.
44Chapter 4. XML Models
- Advanced DTD Concepts
- Can skip this section with subtopics as follows
- Internal and External Subsets
- See Listing 4.5.
- Public Identifier.
- Standalone Documents.
- Entities.
- General and Parameter Entities.
- Internal and External Entities
- See Listings 4.6 and 4.7.
- Parsed, Unparsed Entities, and Notation.
- Conditional Sections
- See Listing 4.8.
45Chapter 4. XML Models
- The Schema Syntax
- Improve on DTDs by supporting more data types
(see Appendix B) and namespaces and using the XML
syntax. - See Listing 4.9 (an XML document that describes
other XML documents!) - Exercise Validate Listing 4.10 with Listing 4.9
in XML Spy 4.2. - XML Schema in for the address used so far, but is
not strictly identical to the DTD because it uses
advanced DTD features.
46Chapter 4. XML Models
- The Schema Syntax (continued)
- Simple Type Definitions
- Atomic (string, integer, boolean, and more).
- Complex Type Definitions
- Aggregate simple types.
- Simple and Complex Content
- Example extending a string with a preferred
attribute. - Mixed Content
- A complex type with the mixed attribute.
- Global Element Definitions
- Must contain at least one global declaration for
root of the document.
47Chapter 4. XML Models
- Namespaces and Other Advanced Schema Concepts
- Can skip this section with subtopics as follows
- Introduction
- See Listing 4.11 (declares two global elements
address-book and entry). - References to Global Elements.
- Namespaces and the Document
- See Listing 4.12.
- Rules Global elements must always be qualified
with a namespace prefix. Local elements may or
may not depending on the value of the
elementFormDefault attribute. - Annotations.
- Typically replaces comments with a documentation
element. - More on Global and Local Elements.
- Rule Global elements can become root of XML
documents but local elements cannot. - Name Groups.
- Two forms element and attribute.
48Chapter 4. XML Models
- Modeling XML Documents
- A creative, fun, and rewarding activity.
- Subject of entire books and practice makes
proficient. - Some guidance
- Avoid modeling if you can.
- It often pays to reuse someone elses models.
- Search the Internet for similar applications and
their XML models. - Take the model that almost works and extend it in
your own namespace.
49Chapter 4. XML Models
- Modeling Documents from an Object Model
- Two examples
- Start from an object model (uses XML Schema).
- Create a new model from scratch (uses DTD) (next
section). - Unified Modeling Language (UML) used for
designing applications written in object-oriented
programming languages (Java, C) can be used
with XML! - Read example on pages 121-128.
- Translated this model to XML by deciding on the
root and drawing a tree to express object
relationships. - Iterate to improve the document logic, navigation
and data extraction. - Create a few sample documents to evaluate it. See
Listing 4.13 and 4.14. - Create the XML Schema for the final model. See
Listing 4.15. - Exercise Validate Listing 4.14 with Listing 4.15
in XML Spy 4.2.
50Chapter 4. XML Models
- Modeling from Scratch
- Have to do the object model analysis as well as
the conversion to XML. - Variation modify an existing XML model, use a
different namespace, and create and analyze
sample documents to improve. - Flexibility, Extensibility, and Usability
(revisit in Chapter 10) - Provide enough structural information to allow
for evolution. - Changes will come from where you least expect
them. - There is no fool-proof solution experience
improves skills. - See if applicable standards exist (e.g. RFC 2426
vCard standard for electronic business cards). - Study how the sample XML document in Listings
4.17 was created from Listing 4.16. - The author considers converting the model into a
DTD or XML Schema to be trival!
51Chapter 4. XML Models
- A Tool to Help
- XML Authority from TIBCO/Extensibility
- http//www.extensibility.com
- Part of XML Canon/Developer Portal for enterprise
XML asset management. - See Unit 5 for tutorials and training materials.
- XML Spy 4.2 from Altova
- http//www.xmlspy.com
- Also see Unit 5 for tutorials and training
materials.
52Chapter 4. XML Models
- Code listings
- Page 91 4.1 abook-dtd.xml
- Page 92 4.2 abook-dtd.dtd
- Page 96 4.3 entry-dtd.xml
- Page 97 4.4 entry-invalid-dtd.xml
- Page 99 4.5 card.xml
- Page 102 4.6 states-provinces.ent
- Page 103 4.7 entry-entity.xml
- Page 104 4.8 Using Conditional Sections (not
in folder) - Page 105 4.9 abook-wo-ns.xsd
- Page 107 4.10 abook-wo-ns.xml
- Page 112 4.11 abook-wt-ns.xsd
- Page 116 4.12 abook-wt-ns.xml
- Page 123 4.13 account-sample.xml
- Page 125 4.14 accounts.xml
- Page 126 4.15 accounts.xsd
- Page 129 4.16 The Address Book in Plain Text
(not in folder) - Page 130 4.17 Sample Address Book (not in
folder) - Also comments-invalid-wo-ns.xml,
comments-invalid-wt-ns.xml, conditional.xml,
conditional.xsd?, entry-wo-ns.xml, and
entry-wt-ns.xml
53Chapter 5. XSL Transformations
- This chapter
- Convert XML documents to HTML, or another XML
markup. - Publish a large set of documents.
- Reorganize XML documents to create table of
contents or other information.
54Chapter 5. XSL Transformations
- Contents
- Why Styling?
- XSL
- Basic XSLT
- Supporting Different Markup Languages
- When and Where to Use Style Sheets
- Advanced XSLT
55Chapter 5. XSL Transformations
- Why Styling?
- XML concentrates on the structure and styling
instructions are organized in stylesheets - CSS (Cascading Style Sheets) (W3C
Recommendation) - Originally developed for HTML, but extended for
XML. - A set of rules that tells the browser which font,
style, and margin to use to display the text. - XSL (eXtensible Stylesheet Language) (W3C
Recommendation) - More ambitious than CSS because it includes a
scripting language (XSLT) to manipulate XML
documents. - Create table of contents, compile an index, and
much more (e.g. XIL in NextPages LivePublish and
NXT 3).
56Chapter 5. XSL Transformations
- XSL
- Organized in two parts
- XSLT (XSL Transformations) (this chapter)
- Concepts
- A language to specify transformations on XML
documents (XML document and an XSLT into an XSL
processor yields a new XML document). - Some possible applications
- Add new elements, create new content (e.g. table
of contents), extract information, convert
between different XML vocabularies or models, and
transform XML documents into HTML for backward
compatibility. - Need an XSLT processor (add-ins to XML Spy 4.2).
- http//www.xmlspy.com/download_components.html
57Chapter 5. XSL Transformations
- XSL
- Organized in two parts (continued)
- FO (Formatting Objects) (next chapter)
- Very similar in scope to CSS.
- Need a FO processing engine (Apache FOP)
- http//www.xmlspy.com/download_components.html
58Chapter 5. XSL Transformations
- Basic XSLT
- Viewing XML in the Browser
- Listing 5.1 (displays collapsible elements).
- A Simple Style Sheet (override the default
behavior) - Listing 5.2 (parts explained in pages 147-154).
- Exercise Use XML Spy 4.2 to display Listings 5.1
and 5.2. Do XSL, Assign XSL, Window, select open
file, and Okay. Do XSL, XSL transformation.
View, Browser view. The result is Listing 5.3. - Additional explanation in pages 147-154.
59Chapter 5. XSL Transformations
- Supporting Different Markup Languages
- Now mostly browsers, but more Net Appliances in
the future which require new markup language to
address the limitations of these new devices
(e.g. WML for small phone screens and slow
connections). - Maintain one XML document and convert it to
different markup languages. - WML is like HTML (the root is wml instead of
html). - Example Apply Listing 5.4 (XSL) to an XML
document to produce a WML document and render it
in a WAP-enabled smartphone. - Download a phone emulator or usew the Opera
browser - http//forum.nokia.com
- http//www.opera.com
60Chapter 5. XSL Transformations
- When and Where to Use Style Sheets
- So far the browser never sees XML as the only
safe option because of limited XSLT support. - Applying a XSL in the browser
- Exercise Use XML Spy 4.2 to display Listings 5.5
and 5.6. Do XSL, Assign XSL, Window, select open
file, and Okay. Do XSL, XSL transformation.
View, Browser view.
61Chapter 5. XSL Transformations
- Advanced XSLT
- So far only used a subset of it with the
structure of the new document close to the
structure of the original document. - Create documents that bear little resemblance to
the original one and redo large Web sites in
minutes. - Creating a table of contents
- Exercise Use XML Spy 4.2 to display Listings 5.7
and 5.1. Do XSL, Assign XSL, Window, select open
file, and Okay. Do XSL, XSL transformation.
View, Browser view. - More explanation on pages 168-172.
62Chapter 5. XSL Transformations
- Code listings
- Page 141 5.1 excerpt.xml
- Page 144 5.2 basic.xsl
- Page 146 5.3 basic.html (not in folder)
- Page 156 5.4 smartphone.xsl
- Page 161 5.5 ie5.xml
- Page 162 5.6 ie5.xsl
- Page 165 5.7 fun.xsl
- Page 172 5.8 rigid.xsl
63Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- This chapter
- Builds on the previous one.
- How to display XML without converting to HTML.
- How to convert XML to PDF (Portable Document
Format, the Adobe Acrobat file format). - How to customize an XML editor for author comfort.
64Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Contents
- Rendering XML Without HTML
- The Basics of CSS and FO
- Simple CSS
- Simple FO
- Flow Objects and Areas
- Property Values
- Box Properties
- Text and Font Properties
- Some Advanced Features
- When Should You Use Which
65Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Rendering XML Without HTML
- Think of FO as a more sophisticated replacement
for HTML. - Convert XML documents to FO, not HTML.
- FO is
- A fixed set of elements.
- Significantly greater control over presentation
than HTML. - Better suited for printing (FO to PDF!).
- See Figure 6.1 on page 177 for differences
between the three - XML (XSLT) to HTML to browser, XML (XSLT) to FO
(to PDF) to browser and printer, and XML (CSS) to
just browser.
66Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- The Basics of CSS and FO
- CSS was originally drafted for HTML, but As HTML
grew Web pages became more complex, more
difficult to read and maintain and slower to
download. - XML was the solution and CSS also works with XML.
- Three versions of CSS from W3C
- CSS1
- Internet Explorer 5.0 an 5.5 support it.
- CSS2 builds on CSS1 and improves XML support.
- Netscape 6.0 and Opera 5.0 support it.
- CSS3 is under development.
67Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Simple CSS
- Listing 6.1 (non-XML syntax) displays Listing 6.2
(XML syntax) in the browser which is the
processor (no special XSLT processor). - Pages 182-183 explore the style sheet in more
detail.
68Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Simple FO
- Need to take advantage of the benefits of using
semantic-rich markup with a target language that
describes how to format documents with complex
designs and printing. - FO is a better target language than HTML, has
rich graphic primitives, and is ideally suited
for printing. - FO is still under development by the W3C, but
major changes are not expected.
69Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Simple FO (continued)
- FO appears as a rewriting of CSS properties in
XML markup with elements and attributes for all
CSS properties. - FO improves on CSS by offering more options, such
as hyperlinks and proper page management. - Exercise Use the XSLT processor with Listing 6.3
to create an XML document (see Listing 6.4) which
is similar to Listing 6.2 but the markup is now
FO. The use the FO (Listing 6.4) in PDF format
using an FO processor (Apache FO). Do in XML Spy
4.2.
70Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Simple FO (continued)
- XML Spy 4.2 User Reference, XSL Menu
- 1. Open a FO document in XML Spy. This example
uses the tiger.fo document in the tutorial
folder. - 2. Select the menu option XSL XSLFO or click
the FO icon in the title bar. This opens the
"Choose XSLFO output" dialog box. - 3. Clicking OK, causes the FO document to be
transformed and displayed in the FOP viewer.
Click the Next icon in the viewer, to see the
next page of this document. - 4. Close the window viewer window when you want
to return to XML Spy. Click the print icon to
print icon if you want to print the document. - 5. Clicking the "Generate output file" radio
button enables you to select the specific type of
output you want to create. Confirming with OK
creates the output you choose.
71Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
72Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
73Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
74Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
75Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
76Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- When Should You Use Which
77Chapter 6. XSL Formatting Objects and Cascading
Stylesheets
- Code listings
- Page 179 6.1 basic.css
- Page 180 6.2 excerpt.xml
- Page 184 6.3 basic.xsl
- Page 186 6.4 basic.fo
- Page 193 6.5 boxes.xsl
- Page 201 6.6 smart.xsl
- Also basic.pdf and smart.pdf
78Chapter 7. The Parser and DOM
- This chapter
- What an XML parser is.
- How to interface a parser with an application.
- What DOM, the Document Object Model, is.
- How to write JavaScript applications that use
DOM. - How to write Java applications that use DOM.
- Which other applications use DOM.
79Chapter 7. The Parser and DOM
- Contents
- What Is a Parser?
- The Parser and the Application
- Document Object Model
- Getting Started with DOM
- Managing the State
- Common Errors and How To Solve Them
- DOM and Java
- DOM in Applications
80Chapter 7. The Parser and DOM
- Code listings
- Page 215 7.1 products.xml
- Page 220 7.2 conversion-ie5.html
- Page 230 7.3 conversion-ns6.xml
- Page 232 7.4 common.css
- Page 234 7.5 products2.xml
- Page 235 7.6 stateful.html
- Page 242 7.7 conversion.java
- Page 245 7.8 showparser.html
- Page 246 7.9 controls.html
- Page 248 7.10 products3.xml
- Also build.xsl and products3.css
81Chapter 8. Alternative API SAX
- This chapter, SAX
- Is an event-based API (Application Programming
Interface). - Operates at a lower level than DOM.
- Gives you more control than DOM.
- Is almost always more efficient than DOM.
- But, unfortunately, requires more work than DOM.
82Chapter 8. Alternative API SAX
- Contents
- Why Another API?
- SAX The Power API
- Commonly Used SAX Interfaces and Classes
- Maintaining the State
- Flexibility
83Chapter 8. Alternative API SAX
- Code listings
- Page 256 8.1 pricelist.xml
- Page 260 8.2 Cheapest.java
- Page 271 8.3 xtpricelist.xml
- Page 272 8.4 BestDeal.java
- Also build.xsl and classpath.bat
84Chapter 9. Writing XML
- This chapter, learn how to write documents
- Through DOM, which is ideal for modifying XML
documents. - Through your own generator, which is more
efficient.
85Chapter 9. Writing XML
- Contents
- The Parser Mirror
- Modifying a Document with DOM
- Exploring Netscape Support for DOM
- DOM Methods to Create and Modify Documents
- Creating a New Document with DOM
- Using DOM to Create Documents
- Creating Documents Without DOM
- Doing Something with the XML Documents
- Writing with Flexibility in Mind
86Chapter 9. Writing XML
- Code listings
- Page 289 9.1 conversion-ie5.html
- Page 294 9.2 conversion-ns6.xml
- Page 297 9.3 common.css
- Page 301 9.4 ProductsCreator.java
- Page 307 9.5 editor.html
- Page 315 9.6 Script to Post an XML Document
Through XMLHTTP (not in folder) - Page 317 9.7 Saving ML Documents with
Microsoft Parser (not in folder) - Page 318 9.8 multi.html
- Also build.xsl, alternative-post.java, and
dump.bat
87Chapter 10. Important XML Models
- This chapter
- How to take advantage of XML extensibility
through namespaces. - Some standards under development by the W3C.
- Warning signs that may point to problems in an
XML document. - The raging debate in the XML community
attributes versus elements.
88Chapter 10. Important XML Models
- Contents
- Structured and Extensible
- XLink
- XHTML
- E-commerce, XML/EDI, and ebXML
- The Right Level of Abstraction
- Attributes Versus Elements
89Chapter 10. Important XML Models
- Code listings
- Page 327 10.1 docbook.xml
- Page 329 10.2 signed.xml
- Page 333 10.3 view.xsl
- Page 340 10.4 extended-xlink.xml
- Page 348 10.5 products-el.xml
- Page 349 10.6 e12at.xsl
- Page 349 10.7 products-at.xml
- Page 350 10.8 at2el.xsl
- Page 350 10.9 el2html.xsl
- Page 351 10.10 products.html
- Page 355 10.11 order.dtd
- Page 357 10.12 order.xml
- Also actuate-xlink.xml?, extended-simple.xsl?,
signed.html, and simple-xlink.xsl?
90Chapter 11. N-Tiered Architecture and XML
- Learned
- How to read and write XML documents as well as
XML models. - How to publish XML documents through style
sheets. - How to manipulate XML documents with a parser.
- This chapter
- How to use XML for interapplication communication
(SOAP-Simple Object Access Protocol). - How XML benefits Web applications and, in
particular, electronic commerce. - How to integrate XML tools in an application
(e.g. XSLT processors).
91Chapter 11. N-Tiered Architecture and XML
- Contents
- What Is an N-Tiered Application?
- The XCommerce Application
- How XML Helps
- Programming SOAP
- XCommerce Architecture
- Server-Side Programming Language
92Chapter 11. N-Tiered Architecture and XML
- Code listings
- Page 372 11.1 Small CORBA Example (not in
folder) - Page 373 11.2 Product Description in HTML (not
in folder) - Page 373 11.3 A List of Products in CSV
(Excel) - Page 375 11.4 Product Description with SOAP
(not in folder) - Page 377 11.5 Excerpt from MerchantService.java
(not in folder) - Page 378 11.6 Deployment Descriptor.xml (not
in folder) - Page 386 11.7 Creating XML with SSJS (not in
folder)
93Chapter 12. Putting It All Together An
e-Commerce Example
- This chapter
- How to use XML in a medium-size application.
- How to organize a three-tiered application using
SOAP. - How XSLT and XML make it easy to build
sophisticated applications. - How to build and install a complete application.
94Chapter 12. Putting It All Together An
e-Commerce Example
- Contents
- Building XCommerce
- First Tier Database
- Second Tier The SOAP Service
- Third Tier The Presentation Servlet
- Utility Class Comparing Strings
95Chapter 12. Putting It All Together An
e-Commerce Example
- Code listings
- Page 394 12.1 web.xml
- Page 395 12.2 jetty.xml
- Page 397 12.3 Deployment Descriptor.xml (not
in folder) - Page 398 12.4 build.xml
- Page 401 12.5 xcommerce.bat
- Page 403 12.6 MerchantConsole.java
- Page 414 12.7 MerchantService.java
- Page 420 12.8 Product.java
- Page 421 12.9 ProductDetails.java
- Page 423 12.10 OrderLine.java
- Page 424 12.11 MallServlet.java
- Page 437 12.12 Mall.xsl
- Page 438 12.13 product.xsl
- Page 441 12.14 Util.java
- Also jetty.bat, readme.html, and
servicemanagerclient.bat
96Appendix A. Crash Course on Java
- This appendix
- That Java is more than a programming language.
- Why Java is important for XML.
- How to install a Java Virtual Machine.
- Enough Java to read and write simple applications.
97Appendix A. Crash Course on Java
- Contents
- Java in Perspective
- Downloading Java Tools
- Your First Java Application
- Servlets
- Your First Servlet
- More Java Language Concepts
98Appendix A. Crash Course on Java
- Code listings
- Page 448 A.1 src\com\psol\xbe2\FixEoL.jar
- Page 461 A.2 src\com\psol\xbe2\XMLGlossary.java
- Page 463 A.3 WEB-INF\classes\com\psol\xbe2\Desc
riptions.properties - Page 463 A.4 WEB-INF\web.xml
- Page 464 A.5 etc\jetty.xml
- Page 467 A.6 WEB-INF\classes\com\psol\xbe2\Desc
riptions_fr.properties - Page 468 A.7 A SAX Interface
- Also build.xsl, fixeol.bat, products.xsl, and
xmlglossary.bat
99Appendix B. DTD and XML Schema Simplified Types
- This appendix summarizes the data types defined
by DTDs and XML Schemas.
100Appendix B. DTD and XML Schema Simplified Types
- Contents
- Simple Types Supported by DTD
- Simple Types Supported by XML Schema