各位仁兄, 帮帮忙吧! haha 我没有,不过,大过年的,帮你顶一下! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jdk的源码?哪有jdk的源码呀?这位仁兄指点明路. 你的jdk中的 .java文件用记事本(推荐用editplus)打开就是啊如果是.class文件可以反编译打开 用过NanoXML吗?life版才6k(两个文件),它完成了XML的基本读写操作,很不错的; 随便找一个开源的xml解析器来改改不就行了 没用过NanoXML, 有源码嘛, 给发个怎样? xerceshttp://xml.apache.org/xerces2-j/index.html 是啊。你看看其他XML解析器实现的方法 package myxml;import javax.xml.parsers.*;import org.w3c.dom.*;import org.apache.crimson.tree.*;import org.xml.sax.SAXException;import java.io.*;public class DomParserDemo{ private Document doc; public DomParserDemo() throws Exception{ DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=factory.newDocumentBuilder(); String source="e:/jhb1117/classes/xmldoc/candidate.xml"; doc=builder.parse(source); } public void showDocument() { //get all <person> NodeList personList=doc.getElementsByTagName(XMLTagDir.NODE_PERSON); //"PERSON" 也可 ,本文中为数据词典 for(int i=0;i<personList.getLength();i++) //节点从0开始 { Element person=(Element)personList.item(i); System.out.print(XMLTagDir.NODE_NAME+": "); System.out.println(getNodeValue(person,XMLTagDir.NODE_NAME)); System.out.print(XMLTagDir.NODE_ADDRESS+": "); System.out.println(getNodeValue(person,XMLTagDir.NODE_ADDRESS)); System.out.print(XMLTagDir.NODE_TEL+": "); System.out.println(getNodeValue(person,XMLTagDir.NODE_TEL)); System.out.print(XMLTagDir.NODE_FAX+": "); System.out.println(getNodeValue(person,XMLTagDir.NODE_FAX)); System.out.print(XMLTagDir.NODE_EMAIL+": "); System.out.println(getNodeValue(person,XMLTagDir.NODE_EMAIL)); System.out.println(); } } public String getNodeValue(Element person,String nodeName){ NodeList nameList=person.getElementsByTagName(nodeName); Element name=(Element)nameList.item(0); Text text=(Text)name.getFirstChild(); String value=text.getNodeValue(); return value; } public void saveDocument(String path) throws IOException { FileWriter fw=new FileWriter(path); XmlDocument xmldoc=(XmlDocument)doc; xmldoc.write(fw); fw.close(); } public static void main(String args[]){ try{ DomParserDemo doc=new DomParserDemo(); doc.showDocument();// String path="e:/houjie/JavaAdvance/dist/xmldoc/parseOut.xml"; String path="e:/jhb1117/classes/xmldoc/jhbparseOut.xml"; doc.saveDocument(path); System.out.print("file saved"); }catch(Exception e){ e.printStackTrace(); } }} package myxml;import javax.xml.parsers.*;import org.w3c.dom.*;import org.apache.crimson.tree.*;import java.io.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author xxy * @version 1.0 */public class DomCreateDemo { private Document doc; public DomCreateDemo() throws Exception{ DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=factory.newDocumentBuilder(); doc=builder.newDocument(); } public void createDocument(){ if(doc==null) return; Element peopleElement=doc.createElement(XMLTagDir.NODE_PEOPLE); for(int i=1;i<=3;i++){ Element personElement=doc.createElement(XMLTagDir.NODE_PERSON); personElement.setAttribute("PERSONID","E"+i); //one person include several tags Text text=null; Element nameElement=doc.createElement(XMLTagDir.NODE_NAME); text=doc.createTextNode("myName"+i); nameElement.appendChild(text); personElement.appendChild(nameElement); Element addressElement=doc.createElement(XMLTagDir.NODE_ADDRESS); text=doc.createTextNode("myAddress"+i); addressElement.appendChild(text); personElement.appendChild(addressElement); Element telElement=doc.createElement(XMLTagDir.NODE_TEL); text=doc.createTextNode("myTel"+i); telElement.appendChild(text); personElement.appendChild(telElement); Element faxElement=doc.createElement(XMLTagDir.NODE_FAX); text=doc.createTextNode("myFax"+i); faxElement.appendChild(text); personElement.appendChild(faxElement); Element emailElement=doc.createElement(XMLTagDir.NODE_EMAIL); text=doc.createTextNode("myEmail"+i); emailElement.appendChild(text); personElement.appendChild(emailElement); peopleElement.appendChild(personElement); } doc.appendChild(peopleElement); } public void saveDocument(String path) throws IOException { FileWriter fout=new FileWriter(path); XmlDocument xmldoc=(XmlDocument)doc; xmldoc.write(fout); fout.close(); } public static void main(String[] args) { try{ DomCreateDemo doc = new DomCreateDemo(); doc.createDocument(); System.out.print("doc created"); String path="e:/jhb1117/classes/xmldoc/jhbcreateOut.xml"; // String path="e:/houjie/JavaAdvance/dist/xmldoc/createOut.xml"; doc.saveDocument(path); System.out.print("file saved"); }catch(Exception e){ e.printStackTrace(); } }} package myxml;import javax.xml.parsers.*;import org.w3c.dom.*;import org.apache.crimson.tree.*;import java.io.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author xxy * @version 1.0 */public class DomCreateDemo { private Document doc; public DomCreateDemo() throws Exception{ DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=factory.newDocumentBuilder(); doc=builder.newDocument(); } public void createDocument(){ if(doc==null) return; Element peopleElement=doc.createElement(XMLTagDir.NODE_PEOPLE); for(int i=1;i<=3;i++){ Element personElement=doc.createElement(XMLTagDir.NODE_PERSON); personElement.setAttribute("PERSONID","E"+i); peopleElement.appendChild(personElement); } doc.appendChild(peopleElement); } public void saveDocument(String path) throws IOException { FileWriter fout=new FileWriter(path); XmlDocument xmldoc=(XmlDocument)doc; xmldoc.write(fout); fout.close(); } public static void main(String[] args) { try{ DomCreateDemo doc = new DomCreateDemo(); doc.createDocument(); System.out.print("doc created");// String path="e:/houjie/JavaAdvance/dist/xmldoc/createOut.xml"; String path="e:/jhb1117/classes/xmldoc/jhbcreateOut.xml"; doc.saveDocument(path); System.out.print("file saved"); }catch(Exception e){ e.printStackTrace(); } }} pache MINA与SNMP4j的问题 如何利用java的多线程对单个文件进行读取 关于stringbuffer的一个问题 判断子进程是不是outOfMemoryError错误 Linux版的JMF使用请教!!急! java将数据库内容保存到数组 java中的drawimage方法? Eclipse中新建类的时候怎样才能有Applet默认的函数paint,init等 怎么得到星期天是7而不是1 ? 接口与继承的区别是什么 java字符串替换出错 使用url如何获取动态网页(*.asp *.jsp)的内容
如果是.class文件可以反编译打开
http://xml.apache.org/xerces2-j/index.html
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.crimson.tree.*;
import org.xml.sax.SAXException;
import java.io.*;public class DomParserDemo{
private Document doc; public DomParserDemo() throws Exception{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
String source="e:/jhb1117/classes/xmldoc/candidate.xml";
doc=builder.parse(source);
} public void showDocument() {
//get all <person>
NodeList personList=doc.getElementsByTagName(XMLTagDir.NODE_PERSON); //"PERSON" 也可 ,本文中为数据词典
for(int i=0;i<personList.getLength();i++) //节点从0开始
{
Element person=(Element)personList.item(i); System.out.print(XMLTagDir.NODE_NAME+": ");
System.out.println(getNodeValue(person,XMLTagDir.NODE_NAME)); System.out.print(XMLTagDir.NODE_ADDRESS+": ");
System.out.println(getNodeValue(person,XMLTagDir.NODE_ADDRESS)); System.out.print(XMLTagDir.NODE_TEL+": ");
System.out.println(getNodeValue(person,XMLTagDir.NODE_TEL)); System.out.print(XMLTagDir.NODE_FAX+": ");
System.out.println(getNodeValue(person,XMLTagDir.NODE_FAX)); System.out.print(XMLTagDir.NODE_EMAIL+": ");
System.out.println(getNodeValue(person,XMLTagDir.NODE_EMAIL)); System.out.println();
}
} public String getNodeValue(Element person,String nodeName){
NodeList nameList=person.getElementsByTagName(nodeName);
Element name=(Element)nameList.item(0);
Text text=(Text)name.getFirstChild();
String value=text.getNodeValue();
return value;
} public void saveDocument(String path) throws IOException
{
FileWriter fw=new FileWriter(path);
XmlDocument xmldoc=(XmlDocument)doc;
xmldoc.write(fw);
fw.close();
}
public static void main(String args[]){
try{
DomParserDemo doc=new DomParserDemo();
doc.showDocument();
// String path="e:/houjie/JavaAdvance/dist/xmldoc/parseOut.xml";
String path="e:/jhb1117/classes/xmldoc/jhbparseOut.xml";
doc.saveDocument(path);
System.out.print("file saved");
}catch(Exception e){
e.printStackTrace();
}
}
}
package myxml;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.crimson.tree.*;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author xxy
* @version 1.0
*/public class DomCreateDemo {
private Document doc; public DomCreateDemo() throws Exception{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
doc=builder.newDocument();
} public void createDocument(){
if(doc==null) return;
Element peopleElement=doc.createElement(XMLTagDir.NODE_PEOPLE);
for(int i=1;i<=3;i++){
Element personElement=doc.createElement(XMLTagDir.NODE_PERSON);
personElement.setAttribute("PERSONID","E"+i); //one person include several tags
Text text=null;
Element nameElement=doc.createElement(XMLTagDir.NODE_NAME);
text=doc.createTextNode("myName"+i);
nameElement.appendChild(text);
personElement.appendChild(nameElement); Element addressElement=doc.createElement(XMLTagDir.NODE_ADDRESS);
text=doc.createTextNode("myAddress"+i);
addressElement.appendChild(text);
personElement.appendChild(addressElement); Element telElement=doc.createElement(XMLTagDir.NODE_TEL);
text=doc.createTextNode("myTel"+i);
telElement.appendChild(text);
personElement.appendChild(telElement); Element faxElement=doc.createElement(XMLTagDir.NODE_FAX);
text=doc.createTextNode("myFax"+i);
faxElement.appendChild(text);
personElement.appendChild(faxElement); Element emailElement=doc.createElement(XMLTagDir.NODE_EMAIL);
text=doc.createTextNode("myEmail"+i);
emailElement.appendChild(text);
personElement.appendChild(emailElement); peopleElement.appendChild(personElement);
}
doc.appendChild(peopleElement);
} public void saveDocument(String path) throws IOException {
FileWriter fout=new FileWriter(path);
XmlDocument xmldoc=(XmlDocument)doc;
xmldoc.write(fout);
fout.close();
} public static void main(String[] args) {
try{
DomCreateDemo doc = new DomCreateDemo();
doc.createDocument();
System.out.print("doc created");
String path="e:/jhb1117/classes/xmldoc/jhbcreateOut.xml";
// String path="e:/houjie/JavaAdvance/dist/xmldoc/createOut.xml";
doc.saveDocument(path);
System.out.print("file saved");
}catch(Exception e){
e.printStackTrace();
}
}
}
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.crimson.tree.*;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author xxy
* @version 1.0
*/public class DomCreateDemo {
private Document doc; public DomCreateDemo() throws Exception{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
doc=builder.newDocument();
} public void createDocument(){
if(doc==null) return;
Element peopleElement=doc.createElement(XMLTagDir.NODE_PEOPLE);
for(int i=1;i<=3;i++){
Element personElement=doc.createElement(XMLTagDir.NODE_PERSON);
personElement.setAttribute("PERSONID","E"+i); peopleElement.appendChild(personElement);
}
doc.appendChild(peopleElement);
} public void saveDocument(String path) throws IOException {
FileWriter fout=new FileWriter(path);
XmlDocument xmldoc=(XmlDocument)doc;
xmldoc.write(fout);
fout.close();
} public static void main(String[] args) {
try{
DomCreateDemo doc = new DomCreateDemo();
doc.createDocument();
System.out.print("doc created");
// String path="e:/houjie/JavaAdvance/dist/xmldoc/createOut.xml";
String path="e:/jhb1117/classes/xmldoc/jhbcreateOut.xml";
doc.saveDocument(path);
System.out.print("file saved");
}catch(Exception e){
e.printStackTrace();
}
}
}