advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Sidebar 1. YAML and Tabs
Sidebar 2. Open Source Project Based on YAML
Partners & Affiliates
advertisement
advertisement
advertisement
Rate this item | 0 users have rated this item.
Email this articleEmail this article
 
Beyond XML and JSON: YAML for Java Developers
Get a high-level introduction to the YAML file format for Java developers. Find out how it differs from XML and JSON and examine its relative advantages and drawbacks. 

advertisement
espite all the buzz generated by dynamic languages (Ruby, Groovy, Python, etc.) and their related frameworks (such as Ruby on Rails), the vast majority of Java developers reading this article deal mostly with pure Java at their day jobs and will continue to do so for many years to come. However, that doesn't mean that they can't learn something from the new kids on the block and add a new tool to their arsenals. This article introduces the YAML (short for YAML Ain't Markup Language) file format (popularized by the Ruby on Rails framework, which uses YAML for all of its configuration files) and shows how it differs from XML and JSON. It goes on to examine YAML's advantages and drawbacks.

Whitespace Indentation and the JSON Option
The YAML file format is centered on the concept of whitespace indentation, which is used to indicate the hierarchical structure of data—instead of nested XML tags or JSON braces ({}) and brackets ([]). It is, however, a superset of JSON. So when it is useful, you may break out of the whitespace flow and adopt a typical JSON-style syntax. Its creators describe it as a "human-friendly data serialization standard for all programming languages." In my experience, its focus on "human-friendliness" is what sets it apart.

Here's a sample of pure YAML using whitespace indentation. Fixed width fonts are critical when creating YAML files, because spacing is crucial (see Sidebar 1. YAML and Tabs):


JFrame:
    defaultCloseOperation: JFrame.EXIT_ON_CLOSE
    title: Test Frame
    width: 800
    height: 400
    components:
        - JTextArea:
             name: textArea1
             text: |
               This is a really long text
               that spans multiple lines (but preserves new lines).
               It does not need to be escaped with special brackets,
               CDATA tags, or anything like that
        - JButton:
             name: button2
             text: Button 2

Depending on your needs, you can switch at any point to JSON-style syntax and mix and match it with whitespace indentation, for example:


JFrame:
    defaultCloseOperation: JFrame.EXIT_ON_CLOSE
    title: Test Frame    width: 800
    height: 400
    components:
        - JTextArea:
             name: textArea1
             text: |
               This is a really long text
               that spans multiple lines (but preserves new lines).
               It does not need to be escaped with special brackets,
               CDATA tags, or anything like that
        - JButton: {name: button2, text: Button 2} #JSON syntax

The ability to switch to JSON-style syntax is especially useful on the lowest-level nodes (i.e., those that have no children of their own). Also, as you've probably guessed, the pound sign (#) is used to embed comments into a YAML file.

  Next Page: Elements of YAML Structure
Page 1: IntroductionPage 3: YAML vs. XML and JSON
Page 2: Elements of YAML Structure 
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES