140 likes | 153 Views
This article explains how XML can be used to present computer programs, including its extensibility and separation of content from presentation. It also discusses the benefits of using XML for universal computing and provides examples of XML implementation in a bookstore and a programming language.
E N D
Using XML to present computer program Qingsong Yao Department of Computer Science York University qingsongy@cs.yorku.ca
What is XML? • eXtensible Markup Language Language for creating other languages • XML is extensible (compared to HTML) user can create new tag and use DTD or Schema to describe the structure of XML file • XML separate content from presentation
WHY XML? • three prerequisites for universal computing: global communication, portable software, and portable data • Java : platform-independent program • Internet :platform-independent networking • XML : platform-independent data.
An 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)>
XML STANDARD • MathML Mathematical Markup Language • SVG (Scalable Vector Graphics) Describe two-dimensional graphics • XML QUERY Access ,query and manipulate the XML • RDF(Resource Description Framework) Interoperable ,machine understandable metadata • more standard can be found on W3C
Using XML • Data Exchange and Translation • e-Commerce Messaging (B2B) • Identical description of data format • Powerful Search Engine and more…
Programming With XML • XML can be represent by an DOM tree element attribute value bookstore book book name=“chapters” name author price name author price Beginning XML 59.95 David Hunter Professional XML Wrox Author Team 74.95
Using XML to present computer language • Background • most computer languages have the same data structure and library • integer , string ,array, and object .. • Searching and Sorting algorithm… • Goals • Present logic ,algorithm or program using XML • Can be transfered into other languages
Data Flow uml corba xml XML Parser Xml Transformer Language Generator Optimizer Dom xml Dom • 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 Pascal Java C file
Key Point • For Object -Orient language , use Java’s grammar to define DTD • For Non-Object-Orient language ,use Pascal ‘s grammar • Each element should have an attribute “ID” in order to be referenced
DTD Example <?xml version="1.0"?> <!ELEMENT variable_define data_type> <!ATTLIST variable_define id (ID | IDREF | IDREFS) #REQUIRED> <!ELEMENT data_type (#PCDATA)> <!ATTLIST data_type id (ID|IDREF|IDREFS) #REQUIRED > <!ELEMENT procedure_declare (parameter*,result*)> <!ATTLIST result data_type> <!ELEMENT procedure (parameters,statements)> <!ATTLIST procedure id (ID|IDREF|IDREFS)
XML 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>
Pascal 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; }
References • W3C XML GROUP (xml standard) http://www.w3.org/XML/ • The XML Industry Portal http://www.xml.org • IBM XML (xml tools and articles) http://www.ibm.com/developer/xml/ http://www.alphaworks.ibm.com/ • SUN XML (java and XML) http://java.sun.com/xml/