Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Creating and Parsing XML Documents in JDeveloper

Oracle's XDK 10G extends JAXP to make reading, writing, and querying XML easy.




Application Security Testing: An Integral Part of DevOps

racle's XDK 10G extends JAXP to make reading, writing, and querying XML easy. One of the first programming exercises for beginning XML developers is to create and parse an XML document. The Java API for XML Parsing (JAXP) includes an API for doing this. Oracle XDK 10g extends the base JAXP capabilities by providing an API in the oracle.xml.parsers.v2 package that overrides some of the classes in the JAXP API and also implements some additional interfaces such as DocumentEditVAL, ElementEditVAL, and NSResolver, which add dynamic validation and aid in using XPath. XDK also provides parser factory and parser classes in the oracle.xml.jaxp package which override the parser classes in the javax.xml.parsers package.

The oracle.xml.parsers.v2 package provides APIs for DOM and SAX parsing. The oracle.xml.jaxp package provides APIs for obtaining parsers for DOM and SAX parsing. This article shows you how to create and parse an XML document using JDeveloper. Listing 1 shows the XML document that you'll create and work with in the examples.

Note that some of the elements and attributes in the example XML document in Listing 1 belong to a specific namespace, http://xdk.com/catalog/journal, denoted by the prefix journal. I've included namespace nodes in the sample document to demonstrate the API's features for creating and parsing namespace nodes. Setting the Environment

Figure 1. JDeveloper XML Application: Here's how the project looks so far in the Applications Navigator.
To get started, download and install Oracle JDeveloper 10.1.3. Create an application workspace in JDeveloper by selecting File—> New—> General—> Application. Specify an application name, XMLParserApp, in the "Create Application" pane and click on the OK button. Specify a project name, XMLParser, in the "Create Project" pane and click on the OK button. Taking those actions adds a new application and a project to the JDeveloper Applications Navigator.

You'll be creating applications that create an XML document, parse an XML document with the DOM API, and parse an XML document with the SAX API. Select your new project node in Applications Navigator and select File—> New—> General—> Java Class. Click on the OK button. The project node is the node with the same name you specified as project name. In the Create Java Class pane, specify a class name ("CreateXMLDocument" for example), a package name, and click on the OK button. Similarly add two more Java applications named "DOMParserApp" and "SAXParserApp" to your JDeveloper project. The result should look like Figure 1.

Next, we need to ensure the XDK parser classes are in the classpath of the XMLParser project. Select the project node in Applications Navigator and select Tools—> Project Properties—> Libraries, and then click on the "Add Library" button to add a library. In the Add Library pane select the Oracle XML Parser v2 library (see Figure 2), and click on the OK button.

Figure 2. Adding a Library: Select the Oracle XML Parser v2 library from the Add Library list.
Figure 3. Project Libraries: You can see and manage the list of libraries added to your project from the Project Properties dialog.
That adds the Oracle XML Parser v2 library to your project's library references (see Figure 3). Click on the OK button in the Project Properties pane to close the dialog.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date