26
06/27/22 06/27/22 Comp Sci 346 Comp Sci 346 1 XML_2 XML_2 Ch. 7 Ch. 7

4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies MathML An application to parse, render, and edit MathML: Amaya

Embed Size (px)

Citation preview

Page 1: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 11

XML_2XML_2

Ch. 7Ch. 7

Page 2: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 22

XML VocabulariesXML Vocabularies

MathMLMathML An application to parse, render, and edit An application to parse, render, and edit

MathML: AmayaMathML: Amaya http://www.w3.org/Amaya/User/BinDist.html

Page 3: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 33

Page 4: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 44

Rendering with AmayaRendering with Amaya

Mathml1.xmlMathml1.xml Mathml2.xmlMathml2.xml Mathml3.xmlMathml3.xml

Page 5: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 55

Mathml1.xmlMathml1.xml<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/mathml2.dtd"><!-- Fig. 14.16: mathml1.mml --><!-- MathML equation. --><math xmlns="http://www.w3.org/1998/Math/MathML"> <mn>2</mn> <mo>+</mo> <mn>3</mn> <mo>=</mo> <mn>5</mn></math>

Page 6: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 66

Mathml2.xmlMathml2.xml<math xmlns="http://www.w3.org/1998/Math/MathML"> <mn>3</mn> <mo>&InvisibleTimes;</mo> <msup> <mi>x</mi> <mn>2</mn> </msup> <mo>+</mo> <mi>x</mi> <mo>&minus;</mo> <mfrac> <mn>2</mn> <mi>x</mi> </mfrac> <mo>=</mo> <mn>0</mn></math>

Page 7: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 77

Mathml3.xmlMathml3.xml<math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <msubsup> <mo>&int;</mo> <mn>0</mn> <mrow> <mn>1</mn> <mo>&minus;</mo> <mi>y</mi> </mrow> </msubsup> <msqrt> <mn>4</mn> <mo>&InvisibleTimes;</mo> <msup> <mi>x</mi> <mn>2</mn> </msup> <mo>+</mo> <mi>y</mi> </msqrt> <mi>&delta;</mi> <mi>x</mi> </mrow></math>

Page 8: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 88

Rendering with Firefox and IERendering with Firefox and IE

Download and install additional fonts for Download and install additional fonts for FirefoxFirefox www.mozilla.org/projects/mathml/fonts/ or or https://developer.mozilla.org/en/Mozilla_MathML_Project/Fonts

Internet Explorer, get a plug in Internet Explorer, get a plug in (Exercise)(Exercise) www.dessci.com/en/products/mathplayer/

Page 9: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 99

Page 10: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1010

Plug-in Mathplayer for IEPlug-in Mathplayer for IE

Page 11: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1111

Page 12: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1212

How to render an XML Document?How to render an XML Document?

Extensible Stylesheet Language (XSL)Extensible Stylesheet Language (XSL) Specify how programs should render XML Specify how programs should render XML

document datadocument data XSL-FO (XSL Formatted Objects)XSL-FO (XSL Formatted Objects)

• Vocabulary for specifying formattingVocabulary for specifying formatting XSLT (XSL Transformation)XSLT (XSL Transformation)

• Defines rules for transforming one XML documment to Defines rules for transforming one XML documment to anotheranother

• From Source tree to Result treeFrom Source tree to Result tree XpathXpath

• Locate parts of the source tree document that match Locate parts of the source tree document that match templates defined in the XSL stylesheettemplates defined in the XSL stylesheet

Page 13: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1313

<?xml version = "1.0"?><?xml:stylesheet type = "text/xsl" href = "games.xsl"?>

<!-- Fig. 20.28 : games.xml --><!-- Sports Database -->

<sports>

<game id = "783"> <name>Cricket</name>

<paragraph> Popular in Commonwealth nations. </paragraph> </game>

Processing Instruction (PI) references the XSL stylesheet games.xsl

Specifies location of XSLT

<? ?> delimits a PI target

Page 14: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1414

<game id = "239"> <name>Baseball</name>

<paragraph> Popular in America. </paragraph> </game>

<game id = "418"> <name>Soccer (Football)</name>

<paragraph> Popular sport in the world. </paragraph> </game>

</sports>

Games.xml continued

Page 15: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1515

XSL style sheetXSL style sheet<?xml version = "1.0"?>

<!-- Fig. 20.29 : games.xsl --><!-- A simple XSLT transformation -->

<!-- reference XSL stylesheet URI --><xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">

<xsl:output method = "html" omit-xml-declaration = "no" doctype-system = "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"/>

<xsl:template match = "/"> <!-- match root element -->

Start style sheet

Binds namespace xsl to W3C XSLT URI

Output as xhtml file. Doctype as xhtml

“/” is used to select the root

Page 16: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1616

Extensible Stylesheet Language (XSL)Extensible Stylesheet Language (XSL)

Element Description <xsl:apply-templates> Applies the templates of the XSL document to the children of

the current node. <xsl:apply-templates match = "expression">

Applies the templates of the XSL document to the children of expression. The value of the attribute match (i.e., expression) must be some XPath expression that specifies elements.

<xsl:template> Contains rules to apply when a specified node is matched. <xsl:value-of select = "expression">

Selects the value of an XML element and adds it to the output tree of the transformation. The required select attribute contains an XPath expression.

<xsl:for-each select = "expression">

Implicitly contains a template that is applied to every node selected by the XPath specified by the select attribute.

<xsl:sort select = "expression">

Used as a child element of an <xsl:apply-templates> or <xsl:for-each> element. Sorts the nodes selected by the <apply-template> or <for-each> element so that the nodes are processed in sorted order.

<xsl:output> Has various attributes to define the format (e.g., xml, html), version (e.g., 1.2, 2.0), document type and media type of the output document. This tag is a top-level element, which means that it can be used only as a child element of a stylesheet.

<xsl:copy> Adds the current node to the output tree. Fig. 20.27 Commonly used XSL stylesheet elements.

Page 17: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1717

Rendering games.xmlRendering games.xml

Page 18: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1818

Using XSLT to Sort and Format DataUsing XSLT to Sort and Format Data

Compare the source in sorting.xml (chapters are out of order) and the rendering

Page 19: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 1919

Page 20: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2020

Other applications using XMLOther applications using XML

DOMDOM PHPPHP

Page 21: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2121

DOMDOM

Document Object ModelDocument Object Model Syntax tree for XML documentSyntax tree for XML document Tree is passed to application (e.g.browser)Tree is passed to application (e.g.browser) Application can modify the document via Application can modify the document via

the treethe tree Browser-independent JavaScript Browser-independent JavaScript

functionalityfunctionality

Page 22: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2222

Use XML with PHPUse XML with PHP

XML functionality is based on libxml2 XML functionality is based on libxml2 librarylibrary Enabled by default on Windows and Enabled by default on Windows and

Linux/UnixLinux/Unix Check for the following with phpinfo()Check for the following with phpinfo()

domdom libxmllibxml simplexmlsimplexml

Page 23: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2323

Parsing XML with PHPParsing XML with PHP

Example 1: Load an xml file into the XML Example 1: Load an xml file into the XML parser and parser and dumpdump the contents the contents Use 25-2xmlload.php to load 25-Use 25-2xmlload.php to load 25-

1messages.xml as an object1messages.xml as an object Dump the contents of the objectDump the contents of the object

Page 24: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2424

Parsing XML with PHPParsing XML with PHP

Example 2: Load an xml file into the XML Example 2: Load an xml file into the XML parser and parser and displaydisplay the contents the contents Load 25-3 books.xml into XML parser 25-Load 25-3 books.xml into XML parser 25-

4xmlparse.php 4xmlparse.php Break up the elementsBreak up the elements and display the contentsand display the contents

Reference on objects in PHPReference on objects in PHPhttp://us2.php.net/manual/en/language.oop5.php#op5.introhttp://us2.php.net/manual/en/language.oop5.php#op5.intro

Page 25: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2525

Parsing XML with PHPParsing XML with PHP

Example 3: Rewrite example 1 to load an Example 3: Rewrite example 1 to load an xml file into the XML parser and xml file into the XML parser and displaydisplay the contentsthe contents Use 25-4xmlload1.php to load 25-Use 25-4xmlload1.php to load 25-

1messages.xml as an object1messages.xml as an object Display the contents of the objectDisplay the contents of the object

What are the changes?What are the changes?

Page 26: 4/17/2015Comp Sci 3461 XML_2 Ch. 7. 4/17/2015Comp Sci 3462 XML Vocabularies  MathML  An application to parse, render, and edit MathML: Amaya

04/21/2304/21/23 Comp Sci 346Comp Sci 346 2626

SummarySummary

Conclusions?Conclusions? Description of dataDescription of data Method of data exchangeMethod of data exchange Well structured filesWell structured files