⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsertest.java

📁 java web services how to program
💻 JAVA
字号:
// ParserTest.java// Parse and display an XML Document.package com.deitel.jws1.xml;// Java core librariesimport java.io.*;import java.util.*;// Java standard extensionsimport javax.xml.parsers.*;import javax.xml.transform.*;import javax.xml.transform.dom.*;import javax.xml.transform.stream.*;// third-party librariesimport org.w3c.dom.*;import org.xml.sax.SAXException;      public class ParserTest {         public static void main( String args[] ) throws Exception   {         // check command-line arguments for file name      if ( args.length != 1 ) {                  // print usage information         System.err.println(             "Usage: java -jar ParserTest.jar filename" );                  System.exit( 1 );      }                     // get a DocumentBuilderFactory for creating      // a DocumentBuilder (i.e., an XML parser)      DocumentBuilderFactory factory =          DocumentBuilderFactory.newInstance();      // get a DocumentBuilder from the DocumentBuilderFactory      DocumentBuilder builder = factory.newDocumentBuilder();      // parse an XML document and create a DOM tree in       // memory      Document document = builder.parse(          new File( args[ 0 ] ) );               // create DOMSource for source XML document      Source xmlSource = new DOMSource( document );      // create StreamResult for transformation result      Result result = new StreamResult( System.out );            // create TransformerFactory for building Transformers      TransformerFactory transformerFactory =         TransformerFactory.newInstance();      // create Transformer for XSL transformation      Transformer transformer =          transformerFactory.newTransformer();            transformer.setOutputProperty( "method", "xml" );      transformer.setOutputProperty( "indent", "yes" );      // transform and deliver content to client      transformer.transform( xmlSource, result );              }}/* ************************************************************************** * (C) Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall.     * * All Rights Reserved.                                                   * *                                                                        * * DISCLAIMER: The authors and publisher of this book have used their     * * best efforts in preparing the book. These efforts include the          * * development, research, and testing of the theories and programs        * * to determine their effectiveness. The authors and publisher make       * * no warranty of any kind, expressed or implied, with regard to these    * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or       * * consequential damages in connection with, or arising out of, the       * * furnishing, performance, or use of these programs.                     * ***************************************************************************/

⌨️ 快捷键说明

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