The Java EE 5 Tutorial

Building and Running the DOM and DOMSource Examples

When you run DOMExample and DOMSrcExample, you can specify one of two sample XML files in the directory tut-install/javaeetutorial5/examples/saaj/dom/:

You can use either of these files when you run DOMExample. You can use domsrc.xml to run DOMSrcExample.

    To build the programs using NetBeans IDE, follow these steps:

  1. In NetBeans IDE, choose Open Project from the File menu.

  2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/saaj/.

  3. Select the dom folder.

  4. Select the Open as Main Project check box.

  5. Click Open Project.

    A Reference Problems dialog appears. Click Close.

  6. Right-click the dom project and choose Resolve Reference Problems.

  7. In the Resolve Reference Problems dialog, select the first of the missing JAR files and click Resolve.

    The missing files are activation.jar, javaee.jar, and appserv-ws.jar.

  8. Navigate to the as-install/lib/ directory.

  9. Select the missing JAR file (activation.jar, for example) and click Open.

    In the Resolve Reference Problems dialog, all the files have green check marks to the left of their names.

  10. Click Close.

  11. Right-click the project and choose Build.

    To run DOMExample using NetBeans IDE, follow these steps:

  1. Right-click the dom project and choose Properties.

  2. Select Run from the Categories tree.

  3. Click Browse next to the Main Class field.

  4. In the Browse Main Classes dialog, select DomExample.

  5. Click Select Main Class.

  6. In the Arguments field, type the following:


    slide.xml
    
  7. Click OK.

  8. Right-click the project and choose Run.

    To run DOMSrcExample using NetBeans IDE, follow these steps:

  1. Right-click the dom project and choose Properties.

  2. Select Run from the Categories tree.

  3. Click Browse next to the Main Class field.

  4. In the Browse Main Classes dialog, select DomSrcExample.

  5. Click Select Main Class.

  6. In the Arguments field, type the following:


    domsrc.xml
    
  7. Click OK.

  8. Right-click the project and choose Run.

To run the examples using Ant, go to the directory tut-install/javaeetutorial5/examples/saaj/dom/.

To run DOMExample using Ant, use the following command:


ant run-dom -Dxml-file=slide.xml

To run DOMSrcExample using Ant, use the following command:


ant run-domsrc -Dxml-file=domsrc.xml

When you run DOMExample using the file slide.xml, you will see output that begins like the following:


     Running DOMExample.
     Name is slideshow
      Attribute name is author
      Attribute value is Yours Truly
      Attribute name is date
      Attribute value is Date of publication
      Attribute name is title
      Attribute value is Sample Slide Show
      Content is: 
...

When you run DOMSrcExample using the file domsrc.xml, you will see output that begins like the following:


     Running DOMSrcExample.
     Header contents:
     Content is: 

     Name is {http://gizmos.com/NSURI}orderDesk
      Attribute name is SOAP-ENV:actor
      Attribute value is http://gizmos.com/orders
     Content is: 
    ...

If you run DOMSrcExample with the file slide.xml, you will see runtime errors.