1.dtd文档以及它的引入方式
//note.dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
//test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to></to>
<from></from>
<heading></heading>
<body></body>
</note>
2.schema约束文档(未弄懂)
<?xml version="1.0" encoding="UTF-8"?>
<note
xmlns="http://www.w3school.com.cn"
xmlns:w3="http://www.w3school.com.cn"
xmlns:se="http://www.sikiedu.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn note.xsd
http://www.sikiedu.com http://www.sikiedu.com/xx/xx/xx.xsd
">
</note>
3.dom文档
xml解析方式
DOM方式
DOM文档对象模型(树形结构)
DOM方式解析,就是把xml文档加载到内存形成树形结构,可以进行增删改的操作。
xml里面的dom
html里面的dom
差不多,都是用来解析标签的,解析成一个树,并得到一个document对象。
以下为元素Element以及元素属性值Attribute的遍历
import java.util.Iterator;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ParseXML {
public static void main(String[] args) throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read("src/NewFile.xml");
Element root = document.getRootElement();
// System.out.println(root.getName());
Iterator<Element> it = root.elementIterator();
while(it.hasNext())
{
Element ele=it.next();
if(ele.getName().equals("good")){
Element name = ele.element("name");
System.out.println(name.getText());
}
// System.out.println(ele.getName());
// Iterator<Attribute> attributes= ele.attributeIterator();
// while(attributes.hasNext()) {
// Attribute ab=attributes.next();
// System.out.println(ab.getName()+":"+ab.getValue());
// }
}
Element ele = null;
ele.elementIterator("good");
}
}
4.用java代码写xml
import java.io.FileWriter;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class CreateXML {
public static void main(String[] args) throws Exception{
Document document = DocumentHelper.createDocument();
Element root = document.addElement("root");
Element author1 = root.addElement("author")
.addAttribute("name", "James")
.addAttribute("location", "UK")
.addText("James Strachan");
Element author2 = root.addElement("author")
.addAttribute("name", "Bob")
.addAttribute("location", "US")
.addText("Bob McWhirter");
FileWriter out= new FileWriter("foo.xml");
document.write(out);
// out.close();
System.out.println("123");
}
}
5.jsp初探
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.util.Date" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
欢迎你!
<%--
//可以任意书写java代码
out.println("当前登录用户:Dwight");
// out.println(new Date());
--%>
</body>
</html>
6.jsp的两个内置对象request和responese
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.io.PrintWriter" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
大家好,我是处理登陆的页面!
<%
String username = request.getParameter("username");//客户端向服务器发送请求
String password = request.getParameter("password");
System.out.println(username+":"+password);
PrintWriter writer = response.getWriter();//给客户端一些响应
writer.println("printWriter");
%>
</body>
</html>
7.