de.julielab.xml.JulieXMLToolsCLI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of julie-xml-tools Show documentation
Show all versions of julie-xml-tools Show documentation
Reads XML using the VTD parser.
/**
* XMLTools.java
*
* Copyright (c) 2012, JULIE Lab.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
*
* Author: faessler
*
* Current version: 1.0
* Since version: 1.0
*
* Creation date: 07.05.2012
**/
/**
*
*/
package de.julielab.xml;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Simple CLI to offer the tools not only as a library.
*
* @author faessler
*
*/
public class JulieXMLToolsCLI {
/**
* @param args
*/
public static void main(String[] args) {
if (args.length < 2) {
System.out
.println("Usage: "
+ JulieXMLToolsCLI.class.getName()
+ " [xml | text] [output directory] [XPath to record ID for output file names]");
System.out
.println("The option 'xml' will result whole XML fragments to be returned in contrast to only text contents.");
System.out
.println("If you specify an output directory, each result record of the first XPath expression will be written to a file.");
System.out
.println("If you specify a record ID XPath, the output file names will correspond to the value of this field. NOTE: This XPath must be given RELATIVE to the first XPath! I.e. without leading / and from the point where the first XPath ended.");
System.exit(1);
}
String fileName = args[0];
String xpath = args[1];
String option = args.length > 2 ? args[2].toLowerCase() : null;
String outputDir = args.length > 3 ? args[3] : null;
String recordIdXPath = args.length > 4 ? args[4] : null;
List