$ tar -ztf jdom-1.0.tar.gz | grep jar$ jdom-1.0/build/jdom.jar jdom-1.0/lib/ant.jar jdom-1.0/lib/jaxen-core.jar jdom-1.0/lib/jaxen-jdom.jar jdom-1.0/lib/saxpath.jar jdom-1.0/lib/xalan.jar jdom-1.0/lib/xerces.jar jdom-1.0/lib/xml-apis.jar
»Home
»SAX
»DOM
»XSLT
»JDOM
»JS
|
JDOMPrzykładAby uruchomić poniższy przykład należy:
import java.io.IOException; import java.io.StringBufferInputStream; import java.util.ArrayList; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; import org.jdom.xpath.XPath; class JoinJDOMChapter { static String HTML_NS = "http://www.w3.org/1999/xhtml"; public static void main(String[] args) throws IOException { try { Element html = new Element("html", HTML_NS); Element body = new Element("body", HTML_NS); html.addContent(body); add_sections(body); Document doc = new Document(html); XMLOutputter outputter = new XMLOutputter(); outputter.output(doc, System.out); } catch (JDOMException e) { System.err.println(e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } catch (InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } } static void add_sections(Element body) throws IOException, InterruptedException, JDOMException { SAXBuilder builder = new SAXBuilder(); Runtime rt = Runtime.getRuntime(); List urls = new ArrayList(); for (int i = 1; i <= 11; i++) { String suffix = (i == 1) ? "" : (i < 10) ? "s0" + i : "s" + i; urls.add("http://www.cafeconleche.org/books/xmljava/chapters/ch14" + suffix + ".html"); } for (int i = 0; i < urls.size(); i++) { Process p = rt.exec(new String[]{ "sh", "-c", "wget --quiet -O - " + urls.get(i) + " | " + "tidy -asxml -quiet -numeric -o temp.xml"}); System.err.println(urls.get(i) + " " + p.waitFor()); XPath div_xpath = XPath.newInstance("/h:html/h:body/h:div/h:div"); div_xpath.addNamespace("h", HTML_NS); Document doc = builder.build("temp.xml"); List nodes = div_xpath.selectNodes(doc); for (int j = 0; j < nodes.size(); j++) { body.addContent(((Element) nodes.get(j)).detach()); } } } } Ekspansja ~ w shelluNależy uważać na reguły ekspansji tyldy w shellu. Przykłady pokazujące inne traktowanie przypisań zmiennych systemowych oraz wartości opcji: $ echo ~:~ /home/lupan:~ $ echo X=~:~ X=/home/lupan:/home/lupan $ export X=~:~ $ echo $X /home/lupan:/home/lupan $ echo -X=~:~ -X=~:~ $ echo --X=~:~ --X=~:~ $ echo -X ~:~ -X /home/lupan:~ |