DOM Tree Scanner in NetBeans 6.1 Beta

by Amit


Say, you have created (or otherwise) a DTD file (for eg. mapping.dtd).

Right-click on it and you will see a option “Generate DOM Tree Scanner” in the pop-up menu that appears. Click on it:

What you will have is a Java class which is all set to be used to scan through your XML file which conforms to your DTD. Its Magic!

In the Java class that is generated, you will see a method:



public void visitDocument() {
.
.
.
}

This will be your entry-point to the DOM scanner.

Just create another Java class:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package softwareraidtool;


import java.io.IOException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
*
* @author amit
*/
public class MappingScannerDemo {


public static void main(String args[]) throws IOException, SAXException{
try{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Create the builder and parse the file
Document doc = factory.newDocumentBuilder().parse("mapping.xml"); //the file you want to parse and which conforms to the DTD
MappingScanner demo = new MappingScanner(doc);

demo.visitDocument();
}catch(ParserConfigurationException pc){

}
}


}

You will have to modify the DOM scanner class to fit your needs. In its original form, it will just parse the XML file.

Here are the files:

HTH, have fun!

Advertisements