91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 368KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-21
  • 語言: Java
  • 標簽: java??xml??dtd??xsd??

資源簡介

文檔中有代碼案例,詳細講解了使用java讀取xml,并附帶有關于xml的dtd講解,里面包含詳細的文檔和代碼案例。和讀取xml所需的jar。

資源截圖

代碼片段和文件信息

package?com.bzjy.test;

import?org.junit.Test;
import?org.w3c.dom.*;
import?javax.xml.parsers.*;
import?java.io.*;

public?class?JavaReadxml?{
//?Document可以看作是xml在內存中的一個鏡像那么一旦獲取這個Document?就意味著可以通過對
//?內存的操作來實現對xml的操作首先第一步獲取xml相關的Document
private?Document?doc?=?null;

public?void?init(String?xmlFile)?throws?Exception?{
//?很明顯該類是一個單例先獲取產生DocumentBuilder工廠
//?的工廠在通過這個工廠產生一個DocumentBuilder
//?DocumentBuilder就是用來產生Document的
DocumentBuilderFactory?dbf?=?DocumentBuilderFactory.newInstance();
DocumentBuilder?db?=?dbf.newDocumentBuilder();
//?這個Document就是一個xml文件在內存中的鏡像
doc?=?db.parse(new?File(xmlFile));
}

//?該方法負責把xml文件的內容顯示出來
public?void?viewxml(String?xmlFile)?throws?Exception?{
this.init(xmlFile);
//?在xml文件里只有一個根元素先把根元素拿出來看看
Element?element?=?doc.getDocumentElement();
System.out.println(“根元素為:“?+?element.getTagName());

NodeList?nodeList?=?doc.getElementsByTagName(“person“);
System.out.println(“book節點鏈的長度:“?+?nodeList.getLength());

Node?fatherNode?=?nodeList.item(0);
System.out.println(“父節點為:“?+?fatherNode.getNodeName());

//?把父節點的屬性拿出來
NamedNodeMap?attributes?=?fatherNode.getAttributes();

for?(int?i?=?0;?i? Node?attribute?=?attributes.item(i);
System.out.println(“book的屬性名為:“?+?attribute.getNodeName()
+?“?相對應的屬性值為:“?+?attribute.getNodeValue());
}

NodeList?childNodes?=?fatherNode.getChildNodes();
System.out.println(childNodes.getLength());
for?(int?j?=?0;?j? Node?childNode?=?childNodes.item(j);
//?如果這個節點屬于Element?再進行取值
if?(childNode?instanceof?Element)?{
//?System.out.println(“子節點名為:“+childNode.getNodeName()+“相對應的值為“+childNode.getFirstChild().getNodeValue());
System.out.println(“子節點名為:“?+?childNode.getNodeName()
+?“相對應的值為“?+?childNode.getFirstChild().getNodeValue());
}
}

}

@Test
public?void?test_xml()?throws?Exception?{
JavaReadxml?parse?=?new?JavaReadxml();
//?我的xml文件放置在項目下
parse.viewxml(“person.xml“);
}
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????23969??2017-01-06?11:52??dtd-xml\DTD文件.docx

?????文件????????607??2017-01-06?10:15??dtd-xml\Read_xml\.classpath

?????文件????????297??2017-06-05?12:54??dtd-xml\Read_xml\.mymetadata

?????文件???????1535??2017-01-06?11:29??dtd-xml\Read_xml\.project

?????文件????????500??2017-01-06?10:13??dtd-xml\Read_xml\.settings\.jsdtscope

?????文件???????1009??2017-01-06?11:30??dtd-xml\Read_xml\.settings\com.genuitec.eclipse.j2eedt.core.prefs

?????文件????????364??2017-01-06?10:13??dtd-xml\Read_xml\.settings\org.eclipse.jdt.core.prefs

?????文件????????462??2017-01-06?11:30??dtd-xml\Read_xml\.settings\org.eclipse.wst.common.component

?????文件????????252??2017-01-06?10:13??dtd-xml\Read_xml\.settings\org.eclipse.wst.common.project.facet.core.xml

?????文件?????????49??2017-01-06?10:13??dtd-xml\Read_xml\.settings\org.eclipse.wst.jsdt.ui.superType.container

?????文件??????????6??2017-01-06?10:13??dtd-xml\Read_xml\.settings\org.eclipse.wst.jsdt.ui.superType.name

?????文件????????365??2017-06-05?12:55??dtd-xml\Read_xml\person.xml

?????文件????????387??2017-06-05?13:13??dtd-xml\Read_xml\pet.dtd

?????文件????????575??2017-06-05?13:13??dtd-xml\Read_xml\pet3.xml

?????文件???????2300??2017-06-05?12:56??dtd-xml\Read_xml\src\com\bzjy\test\JavaReadxml.java

?????文件????????829??2017-01-06?10:13??dtd-xml\Read_xml\WebRoot\index.jsp

?????文件?????????36??2017-01-06?10:13??dtd-xml\Read_xml\WebRoot\meta-INF\MANIFEST.MF

?????文件???????3043??2017-06-05?12:56??dtd-xml\Read_xml\WebRoot\WEB-INF\classes\com\bzjy\test\JavaReadxml.class

?????文件????????462??2017-01-06?11:29??dtd-xml\Read_xml\WebRoot\WEB-INF\web.xml

?????文件?????930816??2017-06-05?13:08??dtd-xml\TP06.ppt

?????文件??????18960??2017-01-06?11:49??dtd-xml\xml文檔.docx

?????文件???????1411??2011-02-28?16:42??dtd-xml\教學演示案例\示例10:按照規范格式保存寵物信息到HTML文檔\TestIO.java

?????文件????????420??2011-02-28?16:42??dtd-xml\教學演示案例\示例1:xhtml文件舉例\example.xhtml

?????文件????????381??2011-02-28?16:42??dtd-xml\教學演示案例\示例2:xml文件舉例\pet1.xml

?????文件????????944??2011-02-28?16:42??dtd-xml\教學演示案例\示例3:使用內部DTD文件\pet2.xml

?????文件????????100??2011-02-28?16:42??dtd-xml\教學演示案例\示例6:使用CSS格式化xml\pet.css

?????文件???????1976??2011-02-28?16:42??dtd-xml\教學演示案例\示例7:使用DOM解析xml文件\TestDOM.java

?????文件????????865??2011-02-28?16:42??dtd-xml\教學演示案例\示例8:使用Reader讀取文件\TestIO1.java

?????文件????????674??2011-02-28?16:42??dtd-xml\教學演示案例\示例9:使用Writer寫文件\TestIO2.java

?????目錄??????????0??2018-03-15?12:50??dtd-xml\Read_xml\WebRoot\WEB-INF\classes\com\bzjy\test

............此處省略29個文件信息

評論

共有 條評論