1 21 22 package nu.xom.samples; 23 24 import java.io.IOException ; 25 26 import nu.xom.Builder; 27 import nu.xom.Document; 28 import nu.xom.Element; 29 import nu.xom.Elements; 30 import nu.xom.ParsingException; 31 32 41 public class XHTMLQualifier { 42 43 public static void main(String [] args) { 44 45 if (args.length == 0) { 46 System.out.println("Usage: java nu.xom.samples.XHTMLQualifier URL"); 47 return; 48 } 49 50 Builder builder = new Builder(); 51 52 try { 53 Document doc = builder.build(args[0]); 54 Element root = doc.getRootElement(); 55 qualify(root); 56 System.out.println(doc.toXML()); 57 } 58 catch (ParsingException ex) { 60 System.out.println(args[0] + " is not well-formed."); 61 System.out.println(ex.getMessage()); 62 } 63 catch (IOException ex) { 64 System.out.println(ex); 65 } 66 67 } 68 69 public static void qualify(Element current) { 70 71 if (current.getNamespaceURI().equals("")) { 72 current.setNamespaceURI("http://www.w3.org/1999/xhtml"); 73 } 74 Elements children = current.getChildElements(); 75 for (int i = 0; i < children.size(); i++) { 76 qualify(children.get(i)); 77 } 78 79 } 80 81 } 82 | Popular Tags |