Parser(String uri) {
   try {
     SAXParserFactory parserFactory = SAXParserFactory.newInstance();
     SAXParser parser = parserFactory.newSAXParser();
     ConfigHandler handler = new ConfigHandler();
     parser.getXMLReader().setFeature("http://xml.org/sax/features/validation", true);
     parser.parse(new File(uri), handler);
   } catch (IOException e) {
     System.out.println("Error reading URI: " + e.getMessage());
   } catch (SAXException e) {
     System.out.println("Error in parsing: " + e.getMessage());
   } catch (ParserConfigurationException e) {
     System.out.println("Error in XML parser configuration: " + e.getMessage());
   }
   // System.out.println("Number of Persons : " + Person.numberOfPersons());
   // nameLengthStatistics();
   // System.out.println("Number of Publications with authors/editors: " +
   //                   Publication.getNumberOfPublications());
   // System.out.println("Maximum number of authors/editors in a publication: " +
   //                           Publication.getMaxNumberOfAuthors());
   // publicationCountStatistics();
   // Person.enterPublications();
   // Person.printCoauthorTable();
   // Person.printNamePartTable();
   // Person.findSimilarNames();
 }
Пример #2
0
  public static void main(String[] args)
      throws SAXException, IOException, ParserConfigurationException {
    FileInputStream input = new FileInputStream("pages_current.xml");

    SAXParser xmlParser = SAXParserFactory.newInstance().newSAXParser();

    DefaultHandler handler = new RecipeParseHandler();

    xmlParser.parse(input, handler);
  }
Пример #3
0
 public void parse() {
   try {
     // Create SAX Parser factory
     SAXParserFactory spfactory = SAXParserFactory.newInstance();
     // Create SAX Parser
     SAXParser parser = spfactory.newSAXParser();
     // Process XML file by given default handler
     parser.parse(new ByteArrayInputStream(data.getBytes()), new XMLParseContent(result, data));
     // parser.parse(new File("tmp.xml"), new XMLParseRevId(userName,result,data));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #4
0
  public static void main(String[] argv) {
    try {
      // SAXパーサーファクトリを生成
      SAXParserFactory spfactory = SAXParserFactory.newInstance();

      // SAXパーサーを生成
      SAXParser parser = spfactory.newSAXParser();

      // XMLファイルを指定されたデフォルトハンドラーで処理します
      String fileName = "dos2unix.mm";

      //      parser.parse(new File("helloworld.xml"), new HelloWorldSax());
      parser.parse(new File(fileName), new HelloWorldSax());

    } catch (Exception e) {

      e.printStackTrace();
    }
  }