'xml'에 해당되는 글 1건

  1. 2013.05.30 xml 노드 검색
프로그래밍/JSP 2013. 5. 30. 13:42

<%@ page language="java" contentType="text/html; charset=EUC-KR"

pageEncoding="EUC-KR"%>

<%  request.setCharacterEncoding("euc-kr");%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>연예인 정보</title>

</head>


<body>

<%@ page import="javax.xml.parsers.*,org.w3c.dom.*"%>

<%

NodeList nodeUrl;

String kind = request.getParameter("find");

String Group = request.getParameter("kind1");

String Group1 = request.getParameter("kind2");

String text = "";

String text1 = "";

String strUrl = "/xml1.xml";

Boolean flag = false;

try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(strUrl);


if(Group1 == ""){

nodeUrl = document.getElementsByTagName(Group);

}else{

nodeUrl = document.getElementsByTagName(Group1);

}


int count = nodeUrl.getLength();


for (int i = 0; i < count; i++) {

Node Find_node = nodeUrl.item(i);

Node Top_node = Find_node.getParentNode();

if(Top_node.getNodeName()!="Entertainer"){

Top_node = Find_node.getParentNode().getParentNode();

}

if (kind.equals(Find_node.getFirstChild().getNodeValue())) {

int length = Top_node.getChildNodes().getLength();

for (int f = 0; f < length; f++) {

text = Top_node.getChildNodes().item(f).getTextContent();

if (!text.trim().equals("")) {

out.println(Top_node.getChildNodes().item(f).getNodeName()+": ");

if(Top_node.getChildNodes().item(f).getChildNodes().getLength() > 1){

int length2 = Top_node.getChildNodes().item(f).getChildNodes().getLength();

for(int j=0; j<length2; j++ ){

text1=Top_node.getChildNodes().item(f).getChildNodes().item(j).getTextContent();

if(!text1.trim().equals("")){

out.println("<br>"+"-"+Top_node.getChildNodes().item(f).getChildNodes().item(j).getNodeName()+": "+text1);

}

}

out.println("<br>");

}else{ out.println(text+"<br>");}

}

}out.println("<br>");

}

}

} catch (Exception e) {

throw e;

}

%>

<body>

</body>

</html>



'프로그래밍 > 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
//