最不通用的做法
public Class yg
{
public int id = -1;
public String name = null;
pubcli String password = null;
public yg(){}
}
public function getYG(Document doc)
{
yg myyg = new yg()
myyg.id = ....;
myyg.name = ...;
myyg.password = ...;
return myyg;
}
public Class yg
{
public int id = -1;
public String name = null;
pubcli String password = null;
public yg(){}
}
public function getYG(Document doc)
{
yg myyg = new yg()
myyg.id = ....;
myyg.name = ...;
myyg.password = ...;
return myyg;
}
解决方案 »
- 请教 关于Spring security 获取在线人数的问题
- 应用程序POST数据
- 如何一次性向数据库插入多条语句?
- 为什么对象池中没有数据了?如何解决?
- 1.在jsp中提交表单共有几种方法,分别是什么?
- 请问corba有用吗?是corba好还是ejb好?是不是有了ejb就不用corba了?是不是有了webservices就不用corba了?
- 如何配置 让JBOSS 3.23 支持SSO
- J2EE应用程序客户端 输入用户和密码后报错?
- 怎样把现有的web应用程序打包成war最方便?
- spring4.0 整合时持久化对象出错。
- 请问JBuilder8里如何将一个完整的项目加进去
- 有一个javaBean,我想在自己的程序里面引入它的一些包,如何做?
public Object getObject(Document doc)
{
..
}只需传入一个doc就可以得到一个对象,不需预先定义。我劝你不要发梦,因为你不知道他的型(type)。你必须要造型。得到Object >> 想取属性 >> 需造形 >> 这个形你怎么来????用集合代替,如map
key - value,近乎 Object。较好解决方案
package com.borland.samples.xml.saxparser;import java.io.IOException;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;public class MySaxParser
extends DefaultHandler {
private static int INDENT = 2;
private static String attList = "";
public static void main(String[] argv) {
if (argv.length != 1) {
System.out.println(
"Usage: java com.borland.samples.xml.saxparser.MySaxParser [URI]");
System.exit(0);
}
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
String uri = argv[0];
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
parserFactory.setNamespaceAware(false);
MySaxParser MySaxParserInstance = new MySaxParser();
SAXParser parser = parserFactory.newSAXParser();
parser.parse(uri, MySaxParserInstance);
}
catch (IOException ex) {
ex.printStackTrace();
}
catch (SAXException ex) {
ex.printStackTrace();
}
catch (ParserConfigurationException ex) {
ex.printStackTrace();
}
catch (FactoryConfigurationError ex) {
ex.printStackTrace();
} } private int idx = 0; //indent
public void characters(char[] ch, int start, int length) throws SAXException {
//instantiates s, indents output, prints character values in element
String s = new String(ch, start, length);
if (!s.startsWith("\n")) {
System.out.println(getIndent() + " Value: " + s);
}
} public void endDocument() throws SAXException {
idx -= INDENT;
System.out.println(getIndent() + "end document");
System.out.println("...PARSING ends"); } public void endElement(String uri, String localName, String qName) throws
SAXException {
if (!attList.equals("")) {
System.out.println(getIndent() + " Attributes: " + attList);
}
attList = ""; System.out.println(getIndent() + "end element");
idx -= INDENT;
} public void startDocument() throws SAXException {
idx += INDENT;
System.out.println("PARSING begins...");
System.out.println(getIndent() + "start document: "); } private String getIndent() {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < idx; i++) {
sb.append(" ");
}
return sb.toString();
} public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
idx += INDENT;
System.out.println('\n' + getIndent() + "start element: " + qName);
if (attributes.getLength() > 0) {
idx += INDENT;
for (int i = 0; i < attributes.getLength(); i++) {
attList = attList + attributes.getQName(i) + " = " +
attributes.getValue(i);
if (i < (attributes.getLength() - 1)) {
attList = attList + ", ";
}
}
idx -= INDENT;
} }}