wizz, 建议你用JDOM试试, 很爽哦~ hehehe ... 而且很可能以后会加入sun的sdk中!http://www.jdom.org/ 如果下下来getAttribute不行的话, 最好把source codes重新编译一下再打个包就好了 :)抱歉, 要去吃饭了, 来不及看你的问题了:p 一会儿见, 祝周末愉快 :)
解决方案 »
- 大家帮我看一下hibernate哪里出错了,第一个应用都这么悲剧的弄不出来
- 为什么没有迫切有外连接
- 一个报错问题
- struts2的小实验 但是tomcat报错了 大侠帮我看看
- 求教displaytag的一些应用
- 关于hibernate的映射问题!!!!!
- SSH框架可以用来开发互联网上网站吗?求解
- 穷人没分,各位帮忙看看:com.informix.asf.IfxASFException: Attempt to connect to database server (online_xxx) failed.
- 字符转换日期比较!!!!
- 什么地方可以下载最新版本的JBOSS和TOMCAT
- JBuilder Enterprise 4 怎样配置J2EE 1.3?
- ejb的finder方法找不到表中char类型数据的问题
java.lang.String localName,
java.lang.String qName,
Attributes atts)
throws SAXException
Receive notification of the beginning of an element.
The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.This event allows up to three name components for each element:the Namespace URI;
the local name; and
the qualified (prefixed) name.
Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:the Namespace URI and local name are required when the namespaces property is true (the default), and are optional when the namespaces property is false (if one is specified, both must be);
the qualified name is required when the namespace-prefixes property is true, and is optional when the namespace-prefixes property is false (the default).
Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
/*
* (C) Copyright IBM Corp. 1999 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.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import org.xml.sax.AttributeList;
import org.xml.sax.HandlerBase;
import org.xml.sax.Parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.ParserFactory; import com.ibm.xml.parsers.SAXParser; /**
* saxOne.java
* This sample program illustrates how to use a SAX parser. It
* parses a document and writes the document抯 contents back to
* standard output.
*/ public class saxOne
extends HandlerBase
{
public void parseURI(String uri)
{
SAXParser parser = new SAXParser();
parser.setDocumentHandler(this);
parser.setErrorHandler(this);
try
{
parser.parse(uri);
}
catch (Exception e)
{
System.err.println(e);
}
}
/** Processing instruction. */
public void processingInstruction(String target, String data)
{
System.out.print("<?");
System.out.print(target);
if (data != null && data.length() > 0)
{
System.out.print(' ');
System.out.print(data);
}
System.out.print("?>");
} /** Start document. */
public void startDocument()
{
System.out.println("<?xml version=\"1.0\"?>");
} /** Start element. */
public void startElement(String name, AttributeList attrs)
{
System.out.print("<");
System.out.print(name);
if (attrs != null)
{
int len = attrs.getLength();
for (int i = 0; i < len; i++)
{
System.out.print(" ");
System.out.print(attrs.getName(i));
System.out.print("=\"");
System.out.print(attrs.getValue(i));
System.out.print("\"");
}
}
System.out.print(">");
} /** Characters. */
public void characters(char ch[], int start, int length)
{
System.out.print(new String(ch, start, length));
} /** Ignorable whitespace. */
public void ignorableWhitespace(char ch[], int start, int length)
{
characters(ch, start, length);
} /** End element. */
public void endElement(String name)
{
System.out.print("</");
System.out.print(name);
System.out.print(">");
} /** End document. */
public void endDocument()
{
// No need to do anything.
} //
// ErrorHandler methods
// /** Warning. */
public void warning(SAXParseException ex)
{
System.err.println("[Warning] "+
getLocationString(ex)+": "+
ex.getMessage());
} /** Error. */
public void error(SAXParseException ex)
{
System.err.println("[Error] "+
getLocationString(ex)+": "+
ex.getMessage());
} /** Fatal error. */
public void fatalError(SAXParseException ex)
throws SAXException
{
System.err.println("[Fatal Error] "+
getLocationString(ex)+": "+
ex.getMessage());
throw ex;
} /** Returns a string of the location. */
private String getLocationString(SAXParseException ex)
{
StringBuffer str = new StringBuffer(); String systemId = ex.getSystemId();
if (systemId != null)
{
int index = systemId.lastIndexOf('/');
if (index != -1)
systemId = systemId.substring(index + 1);
str.append(systemId);
}
str.append(':');
str.append(ex.getLineNumber());
str.append(':');
str.append(ex.getColumnNumber()); return str.toString();
} /** Main program entry point. */
public static void main(String argv[])
{
if (argv.length == 0)
{
System.out.println("Usage: java saxOne uri");
System.out.println(" where uri is the URI of your XML document.");
System.out.println(" Sample: java saxOne sonnet.xml");
System.exit(1);
} saxOne s1 = new saxOne();
s1.parseURI(argv[0]);
}
}