1 2 3 import org.jdom.*; 4 import org.jdom.input.SAXBuilder; 5 import org.jdom.output.*; 6 7 import org.jdom.contrib.ids.IdDocument; 8 import org.jdom.contrib.ids.IdFactory; 9 10 11 public class TestIds { 12 13 public static void main(String [] args) throws Exception { 14 if (args.length < 2) { 15 System.out.println("Usage: java TestIds <XML file> <ID>"); 16 System.exit(2); 17 } 18 19 SAXBuilder builder = new SAXBuilder(); 20 builder.setFactory(new IdFactory()); 21 22 IdDocument doc = (IdDocument)(builder.build(args[0])); 23 Element elt = doc.getElementById(args[1]); 24 25 if (elt != null) { 26 new XMLOutputter(Format.getPrettyFormat()).output(elt, System.out); 27 System.out.println(); 28 System.exit(0); 29 } 30 else { 31 System.out.println("No element with ID \"" + args[1] + "\" found"); 32 System.exit(1); 33 } 34 } 35 } 36 37 | Popular Tags |