5.9总结 Jaxp 解析xml文件两种方式__TOmcat 的配置
1. Jaxp 解析xml文件 Dom方式
<?xml version="1.0" encoding="gbk"?>
<students>
<student id="001">
<name>张三</name>
<age>25</age>
</student>
<student id="002">
<name>李四</name>
<age>23</age>
</student>
<student id="003">
<name>王五</name>
<age>35</age>
</student>
<student id="004">
<name>周六</name>
<age>20</age>
</student>
</students>
1、获取DocumentBuilder对象
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance
2通过工厂获取documentBulider对象
DocumentBuilderFatory document=factory.newDocumentBulider();
3,使用DocumentBuilder对象的解析方法,与xml文件关联。获取该文件的。doucment对象。
Document document = (Document) builder.parse(new File("stu.xml"));
---------------------------------------------------------------------------------------------------------------
2 获取Element:
NodeList list=document.getDocumentElement().getElementsByTagName("student");
for(int i=0;i<list.getLength();i++)
{
Element element=(Element) list.item(i);
NodeList list2=element.getChildNodes();
Node node = list2.item(3);
System.out.println(node.getTextContent()+".."+node.getNodeName()+"..."
+node.getNodeType()+"..."+node.getNodeValue());
}
在以上的程序中 list2.item(3)获取的是studen标签下的age 标签 ,因为空白区域也是占有一个节点
如果改为 Node node = list2.item(2) 就会得到:
&nb
相关文档:
<html>
<head>
<title>XML Demo</title>
</head>
<body>
<script language="javascript">
function window.onload()
{
var domXML=new ActiveXObject("Microsoft.xmldom");
domXML.load("aTest.xml");
var myRoot=domXML.documentElement;
var myNodes2=myRoot.child ......
首先要有一个简易的服务器,建立一个站点,然后站点下存放
1:crossdomain.xml 这个是跨与域策略文件,用于指定域通过Flash
Player访问本域的资源(如果服务器在本机就没有这个必要)但是远程的话就要(建议要)
文件内容:
<cross-domain-policy>
<allow-access-from domain="*" /> ......
class ImportExportToExcel
{
public class ImportExportToExcel
{
private string strConn;
private System.Windows.Forms.OpenFileDialog openFileDlg = new System.Windows.Forms.OpenFileDialog();
private System.Windows.Forms.SaveFileDialog saveFi ......
/*
数据库查询XML结构,FOR XML PATH 语句的应用
*/
FOR XML PATH 语句的应用:
CREATE TABLE TempTable(UserID int , UserName nvarchar(50));
insert into TempTable (UserID,UserName) values (1,'a')
insert into TempTable (UserID,UserName) values (2,'b')
select UserID,UserName from TempTable FOR ......
Integration with the XML Data Type
With the introduction of the XML data type, we wanted to also give FOR XML the ability to generate an instance of XML directly (more precisely, it generates a single row, single column rowset where the cell contains the XML data type instance).
Because of the bac ......