Extensible Markup Language - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Extensible Markup Language

Description:

XML is a markup language which used to define data. ... { public static void main(String argv[]) { Import classes app will use. Set up I/O ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 26
Provided by: usersC1
Category:

less

Transcript and Presenter's Notes

Title: Extensible Markup Language


1
Extensible Markup Language
  • Presented by
  • Billy Jimenez
  • Mike Evans
  • Matt Lietzke
  • Doug Svendsen

2
The Basics
  • What is XML?
  • XML is a markup language which used to define
    data. It can be used across many platforms to
    transmit information
  • What does XML Do?
  • Nothing

3
Uses of XML
  • Separate data from HTML
  • Share and exchange data
  • Store data
  • Make data more useful

4
XML Syntax
  • XML declaration
  • Describe child elements
  • Define the end of the root element
  • lt?xml version"1.0" encoding"ISO-8859-1"?gt
  • ltnotegt
  • lttogtClasslt/togt
  • ltfromgtTeam twolt/fromgt
  • ltheadinggtXMLlt/headinggt
  • ltbodygtThis is what XML looks likelt/bodygt
  • lt/notegt

5
XML Tags
  • All elements of XML must have closing tags
  • ltnotokgtDont do this
  • ltokgtHooray for closing tablt/okgt
  • XML tags are case sensitive
  • ltUpperCasegtNot going to worklt/UPPERCASEgt
  • ltUpperCasegtGoing to worklt/UpperCasegt
  • Must properly nest elements
  • ltingtltordergtnot properly nestedlt/ingtlt/ordergt
  • ltingtltordergtproperly nestedlt/ordergtlt/ingt

6
More on XML Tags
  • Root element is necessary for XML documents
  • ltrootgt
  • ltchildgt.lt/childgt
  • lt/rootgt
  • Always quote attribute values
  • lt?xml version1.0 encodingISO-4234-m
  • White space is preserved in XML
  • Commenting in XML
  • lt! This is how you comment --gt

7
XML Elements
  • XML documents may carry more information than
    what is read and output
  • XML elements have parent/child relationships
  • Element naming rules
  • May not begin with punctuation or a number
  • May not begin with xml or any case combination
  • May not contain spaces
  • Ex. ltcustom_name5gt

8
XML Attributes
  • Attributes may be used to add information about
    elements
  • Attributes written with single or double quotes
  • ltteam team2awesomegt
  • ltteam team2awesomegt
  • If the attribute contains quotes, must use the
    opposite type to include them
  • ltteam team2we are awesomegt
  • ltteam team2we are awesomegt

9
Attributes vs Children
  • Attributes may also be written as child elements
  • ltnote date12/08/2005gt
  • ltdategt
  • ltmonthgt12lt/monthgt
  • ltdaygt08lt/daygt
  • ltyeargt2005lt/yeargt
  • lt/dategt
  • Disadvantages to attributes
  • Cannot contain multiple values
  • Cannot describe structures
  • More difficult for program code to read

10
Sax Parser and Echoing
  • Create a skeleton for the app
  • public class Echo
  • public static void main(String argv)
  • Import classes app will use
  • Set up I/O
  • Implement ContentHandler Interface

11
Setting up the Parser
  • Public static void main(String argv)
  • if(argv.length !1)
  • System.err.println("Usage cmd filename")
  • System.exit(1)
  • DefaultHandler handler new Echo()
  • // Use non-validating parser
  • SAXParserFactory factory SAXParserFactory.newIn
    stance()
  • try
  • // Set up the output stream
  • out new OutputStreamWriter(System.out,
    UTF8)
  • // Parse the input
  • SAXParser saxParser factory.newSASParser()
  • saxParser.parse( new File(argv0), handler )
  • catch(Throwable t)
  • t.printSatckTrace)
  • stystem.exit(0)

12
Write the Output
  • static private Writer out
  • private void emit(String s) throws SAXException
  • try
  • out.write(s)
  • out.flush()
  • catch (IOException e)
  • throw new SAXException("I/O error", e)

13
Space the Output
  • private void nl() throws SAXException
  • String lineEnd System.getProperty("line.separat
    or")
  • try
  • out.write(lineEnd)
  • catch (IOException e)
  • throw new SAXException("I/O error", e)

14
Identify Events
  • To identify events, one must overwrite 5
    important function
  • Start Document()
  • Start element(String namespaceURI,
    String sName, // simple name
    (localName) String
    qName, // qualified name,Attributes attrs)
  • End element (String namespaceURI,
    String sName, // simple name
    String qName // qualified name)
  • Characters(char buf, int offset, int len)
  • End Document()

15
SAX Usages
  • What is SAX Used for?

16
Document Type Definition (DTD)
  • DTD defines the structure of a XML document
  • Lets you specify the kinds of tags and elements
    that can be included in XML documents
  • DTD is a description of an XML files format,
    allowing outside sources to parse it

17
Basic Implementation of DTD
  • DTD tags
  • Syntax
  • lt!ELEMENT element-name categorygt
  • Or lt!ELEMENT element-name (element-content)gt
  • (element-content) allows for nested elements
  • Example
  • lt!ELEMENT note (message)gt
  • lt!ELEMENT message (PCDATA)gt

18
Defining Nested Elements and Text
  • lt!ELEMENT media(song, book, article, movie)gt
  • lt!ELEMENT book(title, author, summary,
    publisher)gt
  • lt!ELEMENT title(PCDATA)gt
  • PCDATA parsed character data or text
  • denotes a special word rather than an element

19
Limitations of DTD
  • Syntax is different from XML
  • No way define what format PCDATA is
  • i.e. only numbers or date
  • DTD can ONLY specify a documents structure, it
    cannot limit content

20
DOM
  • What is DOM?
  • - DOM is an organization of some described data
    that allows the user to access and change the
    data.
  • 1. HTML DOM
  • 2. XML DOM
  • XML DOM
  • Platform and language independent
  • Defines a standard set of objects for XML
  • Is a W3C standard

21
Reading XML into DOM
  • Declaring DOM
  • variableType xmlDoc new ActiveXObject("Microsof
    t.XMLDOM")
  • Error handling
  • - outputs an error file in XML
  • Load the Specified File
  • xmlDoc.load(file_name.xml")

22
Reading XML into DOM
  • Parse the file
  • for each x in xmlDoc.documentElement.childNodes
    document.write(x.nodename)
  • document.write(" ")
  • document.write(x.text)
  • next
  • Manipulate Data
  • nodes xmlDoc.documentElement.childNodes

23
JTree construction from DOM
  • Compress the tree view
  • Make operation selectable
  • Identify nodes

24
Application of XML
  • GML
  • OpenOffice
  • Chemistry
  • Pharmaceuticals
  • Webpage building
  • Contracts
  • Court filings
  • Insurance

25
Sources
  • Ray, Erik T. Learning XML. 2nd ed. Beijing
    Cambridge, Mass. O'Reilly, 2003.
  • Lu, Shiyong, et al. "On the Consistency of XML
    DTDs." Data Knowledge Engineering 52.2 (2005)
    231-47.
  • Armstrong, Eric. "Working with XML
  • The Java API for Xml Processing (JAXP) Tutorial."
    Sun MicroSystems. December 10, 2001. Sun
    Microsystems. 12/05/05 lthttp//java.sun.com/webser
    vices/jaxp/dist/1.1/docs/tutorial/sax/index.htmlgt.
  • "XML DOM Introduction" 2005. W3Schools. 3 Dec.
    2005 lthttp//www.w3schools.com/dom/dom_intro.aspgt.
  • Lake, Ron. "The Application of Geography Markup
    Language (GML) to the Geological Sciences."
    Computers Geosciences 31.9 (2005) 1081-94.
    lthttp//www.sciencedirect.com/science/article/B6V7
    D-4GSJR67-1/2/67d38d2783fcf67313caf1d794a95253gt.
Write a Comment
User Comments (0)
About PowerShow.com