Chapter 3. Using RegexXMLReader from within an Application

Using the RegexXMLReader from within an application is not very much different than using other XMLReader implementions except that it is necessary to give the reader a DOM Node representing the regular expression stylesheet via the setProperty function using the http://regexxmlreader.sourceforge.net/stylesheet-node name, like this:


  String regexStylesheetName = "some-stylesheet.rxl";
  String incomingTextFile    = "some-file.txt";

  File inFile = new File(incomingTextFile);

  XMLReader reader = new RegexXMLReader();
  DOMParser domParser = new DomParser();
  domParser.parse(regexStylesheetName);
  Node stylesheetNode = (Node) domParser.getDocument();   
  reader.setProperty("http://regexxmlreader.sourceforge.net/stylesheet-node", stylesheetNode);
  reader.setContentHandler(this); // for example
  InputSource inputSource = new InputSource(inFile.toURL());
  reader.parse(inputSource);

Other than that, you should be able to use RegexXMLReader in any place that expects an implementation of the XMLReader interface.