Java
  Home arrow Java arrow Page 5 - Integrating XML with J2EE
The Best Selling PC Migration Utility.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Integrating XML with J2EE
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2004-11-16

    Table of Contents:
  • Integrating XML with J2EE
  • Benefits and Characteristics of XML
  • Structure and Syntax of XML
  • Structure of an XML Document
  • Well-formed XML Documents
  • Namespaces
  • Element Type Declarations
  • XML Schemas
  • Parsing XML
  • Parsing XML Using SAX
  • Document Object Model (DOM) Parser
  • Modifying a DOM Tree
  • Java Architecture for XML Binding
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Integrating XML with J2EE - Well-formed XML Documents
    (Page 5 of 14 )

    An XML document is said to be well-formed if there is exactly one root element, it and every sub-element has delimiting start and end tags that are properly nested within each other and all attributes are quoted.

    The following is a simple XML document with an XML declaration followed by a number of elements. The structure represents a list of jobs that could be used in the Agency case study example. In Listing 16.3, the <jobSummary> tag is the root tag followed by a number of jobs.

    Listing 16.3 Example jobSummary XML

    <?xml version ="1.0"?>
    <jobSummary>
    <job>
    <customer>winston</customer>
    <reference>Cigar Trimmer</reference>
    <location>London</location>
    <description>Must like to talk and smoke</description>
    <skill>Cigar maker</skill>
    <skill>Critic</skill>
    </job>
    <job>
    <customer>george</customer>
    <reference>Tree pruner</reference>
    <location>Washington</location>
    <description>Must be honest</description>
    <skill>Tree surgeon</skill>
    </job>
    </jobSummary>

    Attributes

    Attributes are name/value pairs that are associated with elements. There can be any number of attributes, and an element's attributes all appear inside the start tag. The names of attributes are case sensitive and are limited to the following characters: letters, digits, underscores _, periods ., and hyphens -. An attribute name must begin with a letter or underscore.

    The value of an attribute is a text string delimited by quotes, either single or double quotes may be used. Unlike HTML, all attribute values in an XML document must be enclosed in quotes. Listing 16.4 shows the jobSummary XML document re-written to use attributes to hold some of the data.

    Listing 16.4 JobSummary.xml XML with Attributes

    <?xml version ="1.0"?>
    <jobSummary>
    <job customer="winston" reference="Cigar Trimmer">
    <location>London</location>
    <description>Must like to talk and smoke</description>
    <skill>Cigar maker</skill>
    <skill>Critic</skill>
    </job>
    <job customer="george" reference="Tree pruner">
    <location>Washington</location>
    <description>Must be honest</description>
    <skill>Tree surgeon</skill>
    </job>
    </jobSummary>

    The choice of using nested elements or attributes is a contentious area. There are many schools of thought and it usually ends up being a matter of personal taste or corporate standards. Prior to the introduction of XML Schemas (see section "XML Schemas") there were advantages to using attributes when the values were constrained in some way; such as values that are numbers or specific patterns. XML Schemas also allow element values to be constrained in the same way as attribute values.

    Comments

    XML comments are introduced by <!-- and ended with -->, for example

    <!-- this is a comment -->

    Comments can appear anywhere in a document except within the tags, for example,

    <item quantity="1lb">Cream cheese <!-- this is a comment --></item>

    is acceptable, whereas the following is not

    <item <!-- this is a comment --> quantity="1lb">Cream cheese </item>

    Note - As with commenting code, the comments you add to your XML should be factually correct, useful, and to the point. They should be used to make the XML document easier to read and comprehend.


    Any character is allowed in a comment, including those that cannot be used in elements and tags, but to maintain compatibility with SGML, the combination of two hyphens together (--) cannot be used within the text of a comment.

    Comments should be used to annotate the XML, but you should be aware that the parser might remove the comments, so they may not always be accessible to a receiving application.

    This chapter is from Teach Yourself J2EE in 21 Days, second edition, by Martin Bond et. al. (Sams, 2004, ISBN: 0-672-32558-6). Check it out at your favorite bookstore today. Buy this book now.

    More Java Articles
    More By Sams Publishing


     

       

    JAVA ARTICLES

    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup
    - Using RPC-Style Web Services with J2EE
    - Integrating XML with J2EE
    - Taming Tiger: Concurrent Collections

    Iron Speed
     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway