Understanding XML

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

JSTL: JSP Standard Tag Library Kick Start
By Jeff Heaton

Table of Contents
Chapter 8.  Accessing Data with XML Tags


An XML document is a hierarchical file consisting of nodes, attributes, and node values. Listing 8.1 shows a typical XML file. The examples presented in this chapter use this XML file.

Listing 8.1 A Typical XML File (students.xml)
<?xml version="1.0" encoding="ISO-8859-1"?> <students>    <student >       <name>          <first>John</first>          <last>Smith</last>          <middle>T</middle>       </name>       <grade>          <points>88</points>          <letter>B</letter>       </grade>    </student>    <student >       <name>          <first>James</first>          <last>Smith</last>          <middle>K</middle>       </name>       <grade>          <points>92</points>          <letter>A</letter>       </grade>    </student>    <student >       <name>          <first>Kelly</first>          <last>Lane</last>          <middle>A</middle>       </name>       <grade>          <points>72</points>          <letter>C</letter>       </grade>    </student> </students> 

XML files must always have only one top-level node. As you can see in Listing 8.1, the top-level node for this file is the <students> tag. Inside the <students> node are additional nodes, named <student>, for each student. Each of the <student> nodes has an attribute called id. Inside each <student> node is a <name> node, and inside the <name> node are three more nodes: <first>, <last>, and <middle>. These three nodes have node values that contain the student's first name, last name, and middle initial, respectively.

If you are using Microsoft Windows or a Macintosh with Internet Explorer, you can use IE to view the XML file in hierarchical fashion. Simply double-click on the XML file to launch Internet Explorer and display the file, shown in Figure 8.1.

Figure 8.1. Viewing an XML file.

graphics/08fig01.jpg

By viewing the XML file in this way, you will be able to see its hierarchy. Using IE, you can easily expand and collapse branches of the XML file to focus on the data that you are interested in.

It is important to note that the XML standard does not specify how you should name nodes, attributes, or node values. XML is completely free-formed which makes parsing XML challenging. One standard that attempts to help with this is XPath.

Next, we introduce the XML tags and learn how XPath is included. Let's begin by looking at the core XML tags used for basic parsing and access to individual data elements.


    printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
    Top

    [0672324504/ch08lev1sec1]

     
     


    JSTL. JSP Standard Tag Library Kick Start
    JSTL: JSP Standard Tag Library Kick Start
    ISBN: 0672324504
    EAN: 2147483647
    Year: 2001
    Pages: 93
    Authors: Jeff Heaton

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net