|
D:\xmljava\tutorial\xmlprogj>javac
JdomTwo.java:44: 找不到符号
符号: 方法 setTrimAllWhite(boolea
位置: 类 org.jdom.output.XMLOutpu
xo.setTrimAllWhite(true);
方法找不到符号,可能是因为工具包升级了,这里是因为jdom1.1升级左,不用setTrimAllWhite(boolean)方法了.
如果是找不到类,可能是因为路径的错误,没有能够导入类所致.
新的JdomTwo.java
/*
* (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;
import org.jdom.output.Format;
public class JdomTwo
{
public static void main(String[] argv)
{
if (argv.length == 0 ||
(argv.length == 1 && argv[0].equals("-help")))
{
System.out.println("\nUsage: java JdomTwo uri");
System.out.println(" where uri is the URI of your XML document.");
System.out.println(" Sample: java JdomTwo sonnet.xml");
System.out.println("\nUses the JDOM API to parse an XML document, " +
"then write it back to the console.");
System.out.println("This code is different from JDOMOne because it " +
"ignores whitespace.");
System.exit(1);
}
try
{
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(new File(argv[0]));
XMLOutputter xo = new XMLOutputter();
//xo.setTrimAllWhite(true);
xo.setFormat(Format.getCompactFormat());
xo.output(doc, System.out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
} |
|