What the hell is XML - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

What the hell is XML

Description:

What the hell is XML? The Flash Native XML object. Flash Code Example, XML object use. XML Code Example, a file. ... li Lemons /li Paragraph tag ( p ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 21
Provided by: gawainSoc
Category:
Tags: xml | hell | lemons

less

Transcript and Presenter's Notes

Title: What the hell is XML


1
Introduction
  • What the hell is XML?
  • The Flash Native XML object.
  • Flash Code Example, XML object use.
  • XML Code Example, a file.
  • Validating XML, Validation and Correctness.
  • Viewing XML more of this in the tutorial.
  • Showing External (Formatted) Text Files.
  • Supported Tags HTML in text components.

2
What is XML?
  • XML is principally concerned with the description
    and structure of data (content presentation are
    separate).
  • Traditional methods of data storage and exchange
    employ a variety of schemes.
  • Electronically, these usually are of the form of
    simple text files (Comma Separated Values etc.)
    or binary files.
  • Both methods have their own advantages and
    disadvantages.
  • CSV files contain data that can be easily read
    but lack a description of their own format.
  • Binary files contain data and a description of
    its data format (as a Word document does) but are
    proprietary schemes that require specific
    applications to read them.

3
Illustrative Example
  • Paper-based or Simple Text File
  • Yvan Cartwright
  • Staffordshire University
  • y.j.f.cartwright_at_staffs.ac.uk
  • Comma Separated Values
  • Yvan,Cartwright,Staffordshire University,y.j.f.ca
    rtwright_at_staffs.ac.uk
  • Binary a string of 0s and 1s
  • 0101 1001 0111 0110 0110 0001 0110 1110 0010
    0000 etc.

4
Simple freeform XML File
  • ltcontactgt
  • ltnamegt
  • ltfirstnamegtYvanlt/firstnamegt
  • ltlastnamegtCartwrightlt/lastnamegt
  • lt/namegt
  • ltworkplacegtStaffordshire Universitylt/workplacegt
  • ltemailgty.j.f.cartwright_at_staffs.ac.uklt/emailgt
  • lt/contactgt

5
XML Well-formed and Valid
  • The rules for XML files are much stricter than
    for HTML. A forgotten tag, or an attribute
    without quotes makes the file unusable.
  • It is written in the official XML specification
  • Applications are not allowed to try to
    second-guess the creator of a broken XML file
  • If the file is broken, an application has to stop
    right there and issue an error.

6
Native XML object
  • The XML object in Flash MX 2004 is much faster
    than in older versions.
  • It is now a native object, built in to Flash.
  • Also has more functionality (but not XPath).
  • Older versions of Flash XML objects were hard to
    use.
  • XML object follows same rules as other media
    loaders.

7
Code Examples
  • // creates a new, empty XML object
  • var my_xmlXML new XML()
  • // defines how to react to loading of data
  • my_xml.onLoad function(bOkayBoolean)
  • if(bOkay true)
  • trace(my_xml) // success
  • else
  • trace("An error occurred) // oops
  • // now we are ready, try to get the xml data from
    the URL
  • my_xml.load("example.xml")

8
Code Examples
  • Example of HTML-like XML text.
  • Note the contents of the first line.
  • lt?xml version"1.0" encoding"utf-8"
    standalone"yes"?gt
  • ltxhtmlgt
  • ltpgtParagraph ltigtonelt/igt is full of rhubarb,
    rhubarb, rhubarblt/pgt
  • ltpgtPara ltbgttwolt/bgt is also full of rhubarb,
    rhubarb, rhubarblt/pgt
  • ltpgtBut para ltspan class"para3"gt3 contains no
    rhubarblt/spangt!lt/pgt
  • ltpgtFourth, lta href"http//www.staffs.ac.uk/"gta
    link!lt/agtlt/pgt
  • lt/xhtmlgt

9
Validating XML
  • The Flash XML object is not a validator.
  • We have to put good XML in to get good XML out.
  • Badly formed XML will cause unpredictable
    behaviour by a Flash XML object.
  • You should use other software to validate your
    XML as part of your software development and
    testing (e.g. http//www.ltg.ed.ac.uk/richard/xml
    -check.html).

10
Validation and Correctness
  • Remember that valid XML is well structured XML.
  • It doesnt mean that the content is correct!
  • Flash XML objects can be used to build well
    structured XML documents.
  • But the content is up to you!

11
Viewing XML
  • We may choose to use XML in a variety of ways.
  • One way is to use the contents to do something
    for example, custom settings.
  • Or we could use it as dynamic content in a
    text-output area.
  • This is very useful you can develop an
    application separately from the content.

12
External Text Files
  • It is worth using external media files,
    dynamically loaded.
  • Content is easy to update.
  • Content is easy to work on as a team only one
    person needs access to the Flash doc.
  • Simplifies the structure of the Flash doc.
  • Makes the binary (SWF) load faster.
  • Only load what you need.

13
Showing Formatted Text
  • Flash Components include TextArea objects.
  • They can hold HTML formatted text.
  • Limited number of tags supported see next
    slide.
  • Easy to load XML into a TextArea.
  • Supports graphics, links, CSS!

14
Supported Tags
  • Anchor tag (ltagt)
  • lta href"../home.htm" target"_blank"gtGo homelt/agt
  • Supports CSS alink, ahover, and aactive
  • Bold tag (ltbgt)
  • ltbgtThis is bold text.lt/bgt
  • Break tag (ltbrgt)
  • A line of textltbrgtNext line of textltbrgt
  • Font tag (ltfontgt) But USE CSS INSTEAD!
  • ltfont faceArial, Helv" size"24"
    color"0000FF"gtThis is green, 24-point
    textlt/fontgt

15
Supported Tags
  • Image tag (ltimggt) many options.
  • Italic tag (ltigt)
  • That is very ltigtinterestinglt/igt.
  • List item tag (ltligt)
  • ltligtLemonslt/ligt
  • Paragraph tag (ltpgt)
  • textField.htmlText "ltp align'right'gtThis text
    is aligned on the right side of the text
    fieldlt/pgt"
  • Span tag (ltspangt)
  • ltspan classmyCSSstuffgtSome Textlt/spangt
  • Text format tag (lttextformatgt) many options

16
High-Score Tables and XML
  • We now have a mechanism to create XML objects
    within Flash.
  • The information stored inside our XML documents
    is entirely up to us.
  • In a game, we could store the users game
    statistics and send that information to a script.
  • The script could then read the information and
    use it to update an online high score table.

17
High-Score Table Example
  • ltgamegt
  • ltplayergtYvanlt/playergt
  • ltlevelgt5lt/levelgt
  • ltscoregt23518lt/scoregt
  • lttime_takengt756lt/time_takengt
  • lt/gamegt

18
Score Code
  • XML.prototype.ignoreWhite true
  • // the text that goes inside the following
    constructor can be created from the variables in
    your Flash code that hold the required data
  • var packet_xmlXML new XML("ltgamegtltplayergtYvanlt/
    playergtltlevelgt5lt/levelgt ltscoregt23518lt/scoregtlttime_
    takengt756lt/time_takengtlt/gamegt")
  • packet_xml.xmlDecl "lt?xml version\"1.0\" ?gt"
  • packet_xml.send("http//trentdev.soc.staffs.ac.uk/
    wwwdata/isi/highscores.asp", "_blank")
  • // need to code an ASP/PHP/JSP script and put it
    on a server (Part 2!)

19
Reading XML Objects
  • The previous example uses Flash to create an XML
    object and send that to an online server script
    for processing.
  • This can be useful but reading XML objects (or
    documents) within Flash is just as important.
  • You could be sent XML objects from a variety of
    sources including other Flash applications.
  • For games, you can specify input files (level
    content) as an XML document.
  • This could be created using a level editor that
    can export to XML. More on this in Part 2!

20
Conclusion
  • Native XML object is fast
  • Seen some XML code examples
  • Seen an XML example file
  • Discussed validating XML, validation and
    correctness
  • We will view some XML in the tutorial
  • Discussed showing external (formatted) text files
  • Outlined supported tags for further details
    see
  • http//livedocs.macromedia.com/flash/mx2004/main_7
    _2/wwhelp/wwhimpl/common/html/wwhelp.htm?contextF
    lash_MX_2004file00001040.html
Write a Comment
User Comments (0)
About PowerShow.com