using xml to present computer program qingsong yao qingsong yao department of computer science...

14
Using XML to present Using XML to present computer program computer program Qingsong Yao Qingsong Yao Department of Computer Department of Computer Science Science York University York University [email protected] [email protected]

Upload: sherman-dennis

Post on 13-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

Using XML to present Using XML to present computer programcomputer program

Qingsong YaoQingsong Yao

Department of Computer ScienceDepartment of Computer Science

York UniversityYork University

[email protected]@cs.yorku.ca

Page 2: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

What is XML?What is XML?

eXtensible Markup LanguageeXtensible Markup Language Language for creating other languagesLanguage for creating other languages

XML is extensible (compared to HTML)XML is extensible (compared to HTML) user can create new tag and use DTD or Schema to user can create new tag and use DTD or Schema to

describe the structure of XML filedescribe the structure of XML file

XML separate content from presentationXML separate content from presentation

Page 3: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

WHY XML?WHY XML?

three prerequisites for universal three prerequisites for universal

computing: global communication, computing: global communication,

portable software, and portable dataportable software, and portable data

Java : platform-independent program Java : platform-independent program

Internet :platform-independent networkingInternet :platform-independent networking

XML : platform-independent data. XML : platform-independent data.

Page 4: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

An example of XML and DTDAn example of XML and DTD

Bookstore.XML

<?xml version="1.0" encoding="GB2312"??><!DOCTYPE bookstore SYSTEM “Bookstore.DTD”><bookstore name="Chapters"> <book> <name>Beginning XML</name> <author>David Hunter</author> <price>59.95</price> </book> <book> <name>Professional XML</name> <author>Wrox Author Team</author> <price>74.95</price> </book></bookstore>

Bookstore.DTD

<?xml version="1.0"?> <!ELEMENT bookstore (book*)> <!ATTLIST bookstore name (#PCDATA) > <!ELEMENT book (name,author+,price) > <!ELEMENT name (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT price (#PCDATA)>

Page 5: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

XML STANDARDXML STANDARD

MathMLMathML Mathematical Markup LanguageMathematical Markup Language SVG (Scalable Vector Graphics)SVG (Scalable Vector Graphics) Describe two-dimensional graphicsDescribe two-dimensional graphics XML QUERYXML QUERY Access ,query and manipulate the XMLAccess ,query and manipulate the XML RDF(Resource Description Framework)RDF(Resource Description Framework) Interoperable ,machine understandable metadataInteroperable ,machine understandable metadata more standard can be found on W3Cmore standard can be found on W3C

Page 6: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

Using XML Using XML

Data Exchange and TranslationData Exchange and Translation

e-Commerce Messaging (B2B)e-Commerce Messaging (B2B)

Identical description of data formatIdentical description of data format

Powerful Search EnginePowerful Search Engine

and more…and more…

Page 7: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

XML can be represent by an DOM treeXML can be represent by an DOM tree

Programming With XMLProgramming With XML

bookstore

name=“chapters”book book

author pricename author pricename

Beginning XML David Hunter 59.95 Professional XML Wrox Author Team 74.95

element

attribute

value

Page 8: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

Using XML to present computer Using XML to present computer languagelanguage

BackgroundBackground• most computer languages have the same most computer languages have the same

data structure and librarydata structure and library– integer , string ,array, and object ..integer , string ,array, and object ..– Searching and Sorting algorithm…Searching and Sorting algorithm…

GoalsGoals• Present logic ,algorithm or program using Present logic ,algorithm or program using

XMLXML• Can be transfered into other languagesCan be transfered into other languages

Page 9: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

Data FlowData Flow

XML Parser

Optimizer LanguageGeneratorDom Dom

PascalJava C file

xmlumlcorbaxml

Xml Transformer

XML Transformer read source files and convert it to XML File

XML Parser read the XML file, converting it to a DOM tree

XML Optimizer can take grammar check and optimize the DOM tree

Language Generator generate source code from the DOM tree

Page 10: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

Key PointKey Point

For Object -Orient language , use For Object -Orient language , use

Java’s grammar to define DTDJava’s grammar to define DTD

For Non-Object-Orient language ,use For Non-Object-Orient language ,use

Pascal ‘s grammarPascal ‘s grammar

Each element should have an attribute Each element should have an attribute

“ID” in order to be referenced“ID” in order to be referenced

Page 11: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

DTD ExampleDTD Example

<?xml version="1.0"?><?xml version="1.0"?>

<!ELEMENT variable_define data_type><!ELEMENT variable_define data_type>

<!ATTLIST variable_define id (ID | IDREF | IDREFS) #REQUIRED><!ATTLIST variable_define id (ID | IDREF | IDREFS) #REQUIRED>

<!ELEMENT data_type (#PCDATA)><!ELEMENT data_type (#PCDATA)>

<!ATTLIST data_type id (ID|IDREF|IDREFS) #REQUIRED ><!ATTLIST data_type id (ID|IDREF|IDREFS) #REQUIRED >

<!ELEMENT procedure_declare (parameter*,result*)><!ELEMENT procedure_declare (parameter*,result*)>

<!ATTLIST result data_type><!ATTLIST result data_type>

<!ELEMENT procedure (parameters,statements)><!ELEMENT procedure (parameters,statements)>

<!ATTLIST procedure id (ID|IDREF|IDREFS)<!ATTLIST procedure id (ID|IDREF|IDREFS)

Page 12: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

XML Language ExampleXML Language Example

< ?xml version=“1.0” ?>

< procedure id=“square”>

<parameter id=“a”> <data_type id=“integer”> </parameter> <variable_define id=“c”> <data_type id=“integer”> </variable_define>

<assignment id=“c”>

<value> < variable id=“a” />

<operator id=“*” />

<variable id=“a” />

</value>

</assignment>

<procedure_return>

<value > <variable id=“c” /> </value>

</procedure_return>

</procedure>

Page 13: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

Pascal and C Language FilePascal and C Language File

PASCAL

Function square(a:integer):integer

begin

var c: integer;

c:=a * a;

result:=c;

end;

C

int square(int a) {

int c;

c=a*a;

return c;

}

Page 14: Using XML to present computer program Qingsong Yao Qingsong Yao Department of Computer Science Department of Computer Science York University York University

ReferencesReferences

W3C XML GROUP (xml standard)W3C XML GROUP (xml standard) http://www.w3.org/XML/http://www.w3.org/XML/ The XML Industry PortalThe XML Industry Portal

http://www.xml.orghttp://www.xml.org IBM XML (xml tools and articles)IBM XML (xml tools and articles)

http://www.http://www.ibmibm.com/developer/.com/developer/xmlxml// http://www.alphaworks.ibm.com/http://www.alphaworks.ibm.com/ SUN XML (java and XML)SUN XML (java and XML) http://http://javajava.sun.com/.sun.com/xmlxml//