jdomone.java

来自「本站资料仅为大家学习之用」· Java 代码 · 共 49 行

JAVA
49 行
字号
/*
 * (C) Copyright IBM Corp. 2003.  All rights reserved.
 *
 * US Government Users Restricted Rights Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * IBM will not be liable for any damages suffered by you as a result
 * of using the Program. In no event will IBM be liable for any
 * special, indirect or consequential damages or lost profits even if
 * IBM has been advised of the possibility of their occurrence. IBM
 * will not be liable for any third party claims against you.
 */

import java.io.File;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

public class JdomOne
{
  public static void main(String[] argv)
  {
    if (argv.length == 0 ||
        (argv.length == 1 && argv[0].equals("-help")))
    {
      System.out.println("\nUsage:  java JdomOne uri");
      System.out.println("   where uri is the URI of your XML document.");
      System.out.println("   Sample:  java JdomOne sonnet.xml");
      System.out.println("\nUses the JDOM API to parse an XML document, " +
                         "then write it back to the console.");
      System.exit(1);
    }
    try
    {
      SAXBuilder sb = new SAXBuilder();
      Document doc = sb.build(new File(argv[0]));
      XMLOutputter xo = new XMLOutputter();
      xo.output(doc, System.out);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?