advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Deliver On-the-Fly Mapping Services to Your Rich Desktop Java Application, Part 2 :

XML Data Implementation

One of the advantages of starting with an XSD is that many programs, such as Liquid XML Studio, can generate a sample XML document directly from an XSD. Additionally, parsing an XML document that is known as valid, according to an XSD, is a simple task. Listing 2 shows a completed XML implementation that you'll use to obtain tiles from the Open Street Map servers.

At the time of writing this article, the BuildURLFunction element in Listing 2 uses JavaScript which produces identical tile requests to that of the OpenStreetMap.org web site's JavaScript. Placing the logic for tile requests in JavaScript is easy and advantageous when the tile server's JavaScript is well known and understood.

Rather than providing a full example, which demonstrates all the additional metadata features, readers may refer to other XML examples here. The next section will show how to parse the XML.

Parsing Your XML with SAX

Parsing XML in Java is straightforward. When XML can be validated against an XSD, as in this case, then Java XML Binding frameworks such as Apache XMLBeans, or JAXB can make the parsing task easy. If data complexity is not an issue, SAX can also be fairly easy to work with and may be preferred over employing the additional overhead of a Java XML Binding framework. In this case, your XSD is not complex—actually, only a few lines long—so SAX is a good light-weight fit for your XML data.

Parsing XML using SAX requires that you extend the appropriate handler class. You'll extend org.xml.sax.helpers.DefaultHandler in a private inner class of the parser class. The handler simply receives notification of what is happening as the XML is being parsed. The code shown in Listing 3 has been simplified to highlight the parsing process, but click here to view the entire code.

The steps of the parsing algorithm, shown below, are very simple and can be modified for parsing most XML data, granted that it is simple in nature.

  1. The startDocument method performs initialization that is done once.
  2. The startElement method checks for the FactoryInfo element and initializes for this element. This method also initializes the current string buffer.
  3. The characters method captures the text for the current element being processed.
  4. The endElement method copies the current string buffer into a data member of the enclosing parser class. This method also builds a new FactoryInfo structure when processing a FactoryInfo element end tag.
Now, you can parse your XML, which then tells you how to access a tile server.

Home / Articles / Deliver On-the-Fly Mapping Services to Your Rich Desktop Java Application, Part 2 / 1 / 2 / Next Page

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs