Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
Library | Service | Contents | Index

Using XML Parser for Java, 5 of 22

## Running the XML Parser for Java Samples

Table 17-1 lists the XML Parser for Java examples provided with the XDK for Java software. The samples are located in the /sample subdirectory. They illustrate how to use Oracle XML Parser for Java.

##### Table 17-1 XML Parser for Java Samples

Name of Sample File | Description
--- | ---
DOMSample | A sample application using DOM APIs.
SAXSample.java | A sample application using SAX APIs.
XSLSample | A sample application using XSL APIs.
DOMNamespace | A sample application using Namespace extensions to DOM APIs.
SAXNamespace | A sample application using Namespace extensions to SAX APIs.

In addition, because some of the package names are different in V2, difference files were generated to show the differences between V2 and V1 of the XML Parser for Java.

To run the sample programs:

1. Use "`make`" to generate .class files.

2. Add `xmlparserv2.jar` and the current directory to the CLASSPATH.

3. Run the sample program for DOM/SAX APIs as follows:

       java <classname> <sample xml file>

4. Run the sample program for XSL APIs as follows:

       java XSLSample <sample xsl file> <sample xml file>

A few `XML` files such as `class.xml`, `empl.xml`, and `family.xml`, are provided as test cases.

XSL stylesheet `iden.xsl,` can be used to achieve an identity transformation of the supplied XML files:

- class.xml

- NSExample.xml

- family.xml

- empl.xml

### XML Parser for Java - XML Sample 1: class.xml

    <?xml version = "1.0"?>
    <!DOCTYPE course [
    <!ELEMENT course (Name, Dept, Instructor, Student)>
    <!ELEMENT Name (#PCDATA)>
    <!ELEMENT Dept (#PCDATA)>
    <!ELEMENT Instructor (Name)>
    <!ELEMENT Student (Name*)>
    ]>
    <course>
    <Name>Calculus</Name>
    <Dept>Math</Dept>
    <Instructor>
    <Name>Jim Green</Name>
    </Instructor>
    <Student>
    <Name>Jack</Name>
    <Name>Mary</Name>
    <Name>Paul</Name>
    </Student>
    </course>

### XML Parser for Java - XML Example 2: Using DTD employee -- employee.xml

    <?xml version="1.0"?>
    <!DOCTYPE employee [
    <!ELEMENT employee (Name, Dept, Title)>
    <!ELEMENT Name (#PCDATA)>
    <!ELEMENT Dept (#PCDATA)>
    <!ELEMENT Title (#PCDATA)>
    ]>
    <employee>
    <Name>John Goodman</Name>
    <Dept>Manufacturing</Dept>
    <Title>Supervisor</Title>
    </employee>

### XML Parser for Java - XML Example 3: Using DTD family.dtd -- family.xml

    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE family SYSTEM "family.dtd">
    <family lastname="Smith">
    <member memberid="m1">Sarah</member>
    <member memberid="m2">Bob</member>
    <member memberid="m3" mom="m1" dad="m2">Joanne</member>
    <member memberid="m4" mom="m1" dad="m2">Jim</member>
    </family>

#### DTD: family.dtd

    <!ELEMENT family (member*)>
    <!ATTLIST family lastname CDATA #REQUIRED>
    <!ELEMENT member (#PCDATA)>
    <!ATTLIST member memberid ID #REQUIRED>
    <!ATTLIST member dad IDREF #IMPLIED>
    <!ATTLIST member mom IDREF #IMPLIED>

### XML Parser for Java - XSL Example 1: XSL (iden.xsl)

    <?xml version="1.0"?>
    <!-- Identity transformation -->
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:template match="*|@*|comment()|processing-instruction()|text()">
          <xsl:copy>
              <xsl:apply-templates
    select="*|@*|comment()|processing-instruction()|text()"/>
          </xsl:copy>
      </xsl:template>

    </xsl:stylesheet>

### XML Parser for Java - DTD Example 1: (NSExample)

    <!DOCTYPE doc [
    <!ELEMENT doc (child*)>
    <!ATTLIST doc xmlns:nsprefix CDATA #IMPLIED>
    <!ATTLIST doc xmlns CDATA #IMPLIED>
    <!ATTLIST doc nsprefix:a1 CDATA #IMPLIED>
    <!ELEMENT child (#PCDATA)>
    ]>
    <doc nsprefix:a1 = "v1" xmlns="http://www.w3c.org"
    xmlns:nsprefix="http://www.oracle.com">
    <child>
    This element inherits the default Namespace of doc.
    </child>
    </doc>

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index