1 / 32

XML Basics for Digital Humanists

XML Basics for Digital Humanists. Alabama Digital Humanities Center September 19 & 23, 2011 Instructor: Shawn Averkamp, Metadata Librarian smaverkamp@ua.edu. What is XML?. e X tensible M arkup L anguage. L anguage.

helene
Download Presentation

XML Basics for Digital Humanists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Basics for Digital Humanists Alabama Digital Humanities Center September 19 & 23, 2011 Instructor: Shawn Averkamp, Metadata Librarian smaverkamp@ua.edu

  2. What is XML? eXtensible Markup Language

  3. Language • XML is a language for structuring data. (other methods of structuring data: database, excel spreadsheet, etc.) • Not a data model, but a way of encoding a data model or knowledge domain so that it is machine-processable. • XML is composed of syntax rules (just like any other language).

  4. Markup • XML uses “markup” to structure data. • XML uses labels within angle brackets (like in HTML) to “tag” text.

  5. Ingredients 3 avocados 1/4 cup onions 1/4 teaspoon garlic salt 12 corn tortillas 1 bunch fresh cilantro leaves jalapeno pepper sauce

  6. element <ingredients> <ingredient qty=“3”>avocados</ingredient> <ingredient qty=“1/4” unit=“cup”>onions,diced</ingredient> <ingredient qty=“1/4” unit=“t”>garlic salt</ingredient> <ingredient qty=“12”>corn tortillas</ingredient> <ingredient qty=“1”>fresh cilantro leaves</ingredient> <ingredient>jalapeno pepper sauce</ingredient> </ingredients> attribute Elements = things we care about Attributes = properties of those things

  7. eXtensible • You can extend your data model with other XML data models (“schemas”).

  8. The etd schema (in red) “extends” the mods schema <mods> <titleInfo> <title>Pac-man shaped magnetic tunnel junctions for magnetic flip flops for space applications</title> </titleInfo> <name type="personal"> <namePart>Red Ghost<namePart> <role> <roleTerm>Author</roleTerm> </role> </name> <name type="personal"> <namePart>Dot Chomper<namePart> <role> <roleTerm>Advisor</roleTerm> </role> </name> <abstract>Pac-man shaped magnetic tunnel junctions are proposed for CMOS-based magnetic flip flops for space applications…</abstract> <extension> <etd:degree>Ph.D.</etd:degree> <etd:discipline>Electrical and Computer Engineering</etd:discipline> </extension> </mods>

  9. Where is XML? XML drives applications and information you use every day: • RSS feeds (Real Simple Syndication) for blogs, podcasts, more • iTunes stores your music library metadata and usage data in XML • Google uses XML to display geographic data in Google Maps and Earth (more info: http://code.google.com/apis/kml/documentation/kml_tut.html )

  10. What’s XML good for? • Sharing/exchanging data online • Storing data • Controlling data display • Syndication

  11. The XML Family

  12. XML in the Humanities • TEI • Shakespeare Quartos Archive: http://www.quartos.org/ • Lewis & Clark Journals: http://lewisandclarkjournals.unl.edu/ • Syriac Reference Portal: http://www.syriac.ua.edu/

  13. Getting Started • Open Oxygen • Open movies.xml example (in left sample.xpr sidebar) or paste code below into a new document <?xml version="1.0" encoding="UTF-8"?><movies> <movie id="1"> <title>The Green Mile</title> <year>1999</year> </movie> <movie id="2"> <title>Taxi Driver</title> <year>1976</year> </movie> <movie id="3"> <title>The Matrix: Revolutions</title> <year>2004</year> </movie> <movie id="4"> <title>Shrek II</title> <year>2004</year> </movie></movies>

  14. Well-formedness XML documents must be “well-formed” to be machine-readable. • XML documents must have a root element • XML elements must have a closing tag • XML tags are case sensitive • XML elements must be properly nested • XML attribute values must be quoted

  15. Exercise 1 Copy and paste the following code into a new XML document in Oxygen. Correct all errors necessary to make this a well-formed XML document. <movie id=1> <title>The Green Mile<title> <year>1999</year> </movie> <movie id="2"> <title>Taxi Driver</title> <year>1976</year> </movie> <movie id="3"> <title>The Matrix: Revolutions</title> <Year>2004</year> </movie> <movie id="4"> <title>Shrek II</title> <year>2004</movie> </year>

  16. <!-- Comments --> Enclose comments within double-hyphen/angle bracket notation: <!-- a brief comment --> <!-- This is a very long block of comments… … … … more comments… … … comments… (still more comments here…) -->

  17. 5 special symbols To use the following characters in a text value, you must replace them with these entities:

  18. Exercise 2 In your movies.xml document, add another movie to the collection. Add a comment somewhere in the document (or “comment out” a block of elements). When you’ve finished, check for well-formedness (blue check icon).

  19. XML Schemas Schemas describe the syntax rules for encoding a data model in XML: • Allowable elements, attributes, and values • Element types -- simple or complex • Simple – contains a value • Complex – contains other elements • Constraints of elements, attributes, and values • Repeatability (how many instances of each element allowed) • Obligation (is the element or attribute mandatory?) • Datatypes of values(integer, string, date, etc.)

  20. <movies xmlns="http://example.com/schema.xsd"> <movie id="1"> <title>The Green Mile</title> <year>1999</year> </movie> <movie id="2"> <title>Taxi Driver</title> <year>1976</year> </movie> <movie id="3"> <title>The Matrix: Revolutions</title> <year>2004</year> </movie> <movie id="4"> <title>Shrek II</title> <year>2004</year> </movie> </movies>

  21. XML Schemas • Schemas are themselves XML files but with a .xsd file extension. • In our XML document, we reference the schema by using a “namespace”

  22. Namespaces The namespace is the unique identifier for the schema. <mods xmlns=“http://www.loc.gov/mods/v3”> <titleInfo> <title>Pac-man shaped magnetic tunnel junctions for magnetic flip flops for space applications</title> </titleInfo> … … </mods>

  23. Namespace prefixes When two or more schemas are used in an XML document, we use “prefixes” to distinguish between the elements of each. <mods xmlns="http://www.loc.gov/mods/v3" xmlns:etd="http://www.ndltd.org/standards/metadata/etdms/1.0/"> … … <dateIssued>2011</dateIssued> <extension> <etd:degree>Ph.D.</etd:degree> <etd:discipline>Electrical and Computer Engineering</etd:discipline> </extension> </mods>

  24. Valid XML To be “valid” an XML document must: • Be well-formed • Include the schema declaration in the root element (e.g., <mods xmlns=“http://www.loc.gov/mods/v3”>) • Conform to the rules of the schema

  25. Exercise 3 Copy and paste the code on the next slide into a new XML document in Oxygen. Add a <name> element to the document, then validate (red check icon). If it validates, then introduce an error into your document to see what error messages Oxygen gives you.

  26. <mods xmlns="http://www.loc.gov/mods/v3" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:etd="http://www.ndltd.org/standards/metadata/etdms/1.0/" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd" version="3.4"> <titleInfo> <title>Pac-man shaped magnetic tunnel junctions for magnetic flip flops for space applications</title> </titleInfo> <name type="personal"> <namePart>Red Ghost</namePart> <role> <roleTerm>Author</roleTerm> </role> </name> <name type="personal"> <namePart>Dot Chomper</namePart> <role> <roleTerm>Advisor</roleTerm> </role> </name> <abstract>Pac-man shaped magnetic tunnel junctions are proposed for CMOS-based magnetic flip flops for space applications…<abstract> <originInfo> <dateIssued>2011</dateIssued> </originInfo> <extension> <etd:degree>Ph.D.</etd:degree> <etd:discipline>Electrical and Computer Engineering</etd:discipline> </extension> </mods>

  27. Using and creating schemas • Always start with the data model! • Decide what entities and properties are important to youand your project before choosing or creating a schema.

  28. Things to consider • Are there existing schemas that meet your needs?   • Are there commonly used schemas within your field?  • If you find a schema that almost meets your needs, can you extend it to cover the entire scope of what you want to model? • Who (or what software applications) will you be sharing the data with?   • What kind of functionality do you want to support? Indexing? Flexible display? Visualizations?

  29. Tailor schemas to meet your needs • You can make schema rules more strict (but not more lax) • Extend schemas with other schemas (Your primary schema must allow extensions) • If you expect use of your XML data to be very limited, you can change the schema. (Not recommended if you plan to share your data widely or beyond your own software applications)

  30. Documentation • Data dictionaries, markup guidelines, best practices are important, especially if you have assistants entering your data. • Examples of documentation: • MODS guidelines: http://www.loc.gov/standards/mods/userguide/generalapp.html • UVa Library TEI guidelines: http://www.lib.virginia.edu/digital/reports/teiPractices/dlpsPractices_postkb.html

  31. Exercise 4 Work together to create a data model for a dictionary (or a knowledge domain of your choosing). What should the root element be? What are the elements that will be contained within the root? What are the attributes* (properties) of each of your elements? Create an instance of your data model in XML. What adjustments or enhancements would you need to make for your schema to be extensible? *How do you know when something should be an attribute or an element? There is often no wrong answer to this. Use your best judgment—if you think you will not need to further refine a property (for instance, in our recipe example we would not need to refine quantity or unit any further), an attribute is probably the best choice.

  32. Resources • Books, tutorials, and other resources: http://www.lib.ua.edu/digitalhumanities/xml-resources • http://www.xml.com/

More Related