<%@page import="javax.xml.transform.TransformerFactory"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.xml.parsers.*,org.w3c.dom.*,java.io.*, javax.xml.transform.Transformer,
javax.xml.transform.dom.*,javax.xml.transform.stream.*,javax.xml.transform.dom.DOMSource,javax.xml.transform.OutputKeys, java.io.*,java.net.*,java.util.*"%>
<%
request.setCharacterEncoding("UTF-8");
String strUrl = request.getRealPath("/XML")+"/tal.xml";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(strUrl);
NodeList x = document.getElementsByTagName("talent");
int length = x.getLength();
Node last = x.item(length-1);
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String age = request.getParameter("age");
String occupy = request.getParameter("class");
//String sex = request.getParameter("sex");
String c_name = request.getParameter("c_name");
String c_other = request.getParameter("c_other");
String c_address = request.getParameter("c_address");
String c_phone = request.getParameter("c_phone");
String country = request.getParameter("country");
String title_year = request.getParameter("title_year");
String title_name = request.getParameter("title_name");
String height = request.getParameter("height");
String weight = request.getParameter("weight");
%>
<%
try {
//xml 노드 생성 및 붙이기//
Node root = document.getDocumentElement();
Element info = document.createElement("info");
root.appendChild(info);
Element name1 =document.createElement("name");
name1.setTextContent(request.getParameter("name"));
info.appendChild(name1);
Element age1=document.createElement("age");
age1.setTextContent(request.getParameter("age"));
info.appendChild(age1);
Element class1 = document.createElement("class");
class1.setTextContent(request.getParameter("class"));
info.appendChild(class1);
Element sex= document.createElement("sex");
sex.setTextContent(request.getParameter("sex"));
info.appendChild(sex);
Element company = document.createElement("company");
info.appendChild(company);
Element cname= document.createElement("cname");
cname.setTextContent(request.getParameter("c_name"));
company.appendChild(cname);
Element cother= document.createElement("others");
cother.setTextContent(request.getParameter("c_name"));
company.appendChild(cother);
Element caddress= document.createElement("address");
caddress.setTextContent(request.getParameter("c_address"));
company.appendChild(caddress);
Element ctel= document.createElement("tel");
ctel.setTextContent(request.getParameter("c_phone"));
company.appendChild(ctel);
Element county= document.createElement("country");
county.setTextContent(request.getParameter("country"));
info.appendChild(county);
Element jak = document.createElement("jakpum");
info.appendChild(jak);
Element jak_year= document.createElement("year");
jak_year.setTextContent(request.getParameter("title_year"));
jak.appendChild(jak_year);
Element jak_name= document.createElement("title");
jak_name.setTextContent(request.getParameter("title_name"));
jak.appendChild(jak_name);
Element size_=document.createElement("size");
info.appendChild(size_);
Element size_height= document.createElement("height");
size_height.setTextContent(request.getParameter("height"));
size_.appendChild(size_height);
Element size_weight=document.createElement("weight");
size_weight.setTextContent(request.getParameter("weight"));
size_.appendChild(size_weight);
} catch (Exception e){
throw e;
}
try{
TransformerFactory fact = TransformerFactory.newInstance();
fact.setAttribute("indent-number", new Integer(4));
Transformer tran = fact.newTransformer();
tran.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
tran.setOutputProperty(OutputKeys.INDENT, "yes");
tran.setOutputProperty(OutputKeys.METHOD, "xml");
OutputStreamWriter write = new FileWriter(request.getRealPath("/XML")+"/trans.xml");//xml 파일 지정
//StreamResult output = new StreamResult(request.getRealPath("/XML")+"/trans.xml");
tran.transform(new DOMSource(document),new StreamResult(write));
write.flush();
write.close();
}catch(Exception e){
throw e;
}finally{
}
%>
'프로그래밍 > JSP' 카테고리의 다른 글
HttpseverletRequest 정리 (0) | 2014.06.10 |
---|---|
Media query에 대한 이해 (0) | 2014.06.06 |
xml 노드 검색 (0) | 2013.05.30 |
xml 노드 검색 (0) | 2013.05.30 |
jsp DB connection 코드 (0) | 2013.04.20 |