Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > Java Programming > Java Forum > ช่วยแก้ error JAVA Webservice ให้หน่อยค่ะ กำลังศึกษาค่ะแต่ไม่ค่อยเข้าใจ


 

[Java] ช่วยแก้ error JAVA Webservice ให้หน่อยค่ะ กำลังศึกษาค่ะแต่ไม่ค่อยเข้าใจ

 
Topic : 074074

Guest



DOMRead.java

01.import javax.xml.parsers.DocumentBuilderFactory;
02.import javax.xml.parsers.DocumentBuilder;
03.import org.w3c.dom.Document;
04.import org.w3c.dom.Element;
05.import org.w3c.dom.DOMException;
06.import org.w3c.dom.Node;
07.import org.w3c.dom.NodeList;
08.import java.io.IOException;
09.import java.io.File;
10.import javax.swing.JOptionPane;
11. 
12.public class DOMRead1 {
13. 
14. 
15.    public static void main(String[] args) {
16.        String filename="customers.xml";
17.        String output="";
18.        try{
19.            DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();//reserve storage area
20.            DocumentBuilder parser=factory.newDocumentBuilder();//create parser object
21.            Document doc=parser.parse(new File(filename));//read and check document,safe to document object
22.            Element  root=doc.getDocumentElement();//declare element for keep root element
23.            NodeList customerList=root.getElementsByTagName("customer");//has more Contact element
24.            Element emCustomer,temp;//declare child elements in Contact element
25.            Node node;
26.            for(int i=0;i<customerList.getLength();i++){
27.                 
28.                emCustomer=(Element)customerList.item(i);
29.                temp=(Element)emCustomer.getElementsByTagName("customer").item(0);
30.                output+="customer:"+temp.getAttribute("id")+"\n";
31. 
32.                node=temp.getElementsByTagName("Mr").item(0);
33.                output+=temp.getTagName()+"\n";
34.                 
35.                NodeList profileList=temp.getElementsByTagName("profile");
36.                for(int j=0;j<profileList.getLength();j++){
37.                    node=profileList.item(j);
38.                    output+=node.getNodeName()+":"+node.getFirstChild().getNodeValue()+"\n";
39.                }
40.                node=temp.getElementsByTagName("occupation").item(0);
41.                output+="Occupation:"+node.getFirstChild().getNodeValue()+"\n";
42.                 
43.                temp=(Element)emCustomer.getElementsByTagName("birthplace").item(0);
44.                output+="Country:"+temp.getAttribute("county")+"\n";
45.                node=temp.getElementsByTagName("birthplace").item(0);
46.                output+="Birthplace:"+node.getFirstChild().getNodeValue()+"\n";        
47.                output+="\n";
48.                 
49.            }//end loop
50.            JOptionPane.showMessageDialog(null, output);
51.             
52.        }
53.        catch(DOMException d){
54.            d.printStackTrace();
55.        }
56.        catch(IOException io){
57.            io.printStackTrace();
58.        }
59.        catch(Exception e){
60.            e.printStackTrace();
61.        }
62.         
63.         
64.         
65. 
66.    }
67. 
68.}



customers.xml
01.<?xml version="1.0"?>
02.<customers>
03.  <customer id="HO107163">
04.    <Mr />
05.    <profile>
06.      <firstName>Jeff</firstName>
07.      <middleName>Craig</middleName>
08.      <lastName>Rafter</lastName>
09.      <sex>m</sex>
10.      <age>64</age>
11.    </profile >
12.    <occupation >Rector of Ringwould Kent</occupation>
13.    <birthplace county="KEN">Margate</birthplace>
14.  </customer>
15.  <customer id="HO107100">
16.    <Mr />
17.    <profile>
18.      <firstName>Georgiana</firstName>
19.      <middleName>Georgiana</middleName>
20.      <lastName>Monins</lastName>
21.      <sex>f</sex>
22.      <age>39</age>
23.    </profile>
24.    <occupation>Gentlewoman</occupation>
25.    <birthplace>Canterbury</birthplace>
26.  </customer>
27.  <customer id="HO107105">
28.    <Mr />
29.    <profile>
30.      <firstName>Ann</firstName>
31.      <middleName>Anny</middleName>
32.      <lastName>Gaslinge</lastName>
33.      <sex>f</sex>
34.      <age>39</age>
35.    </profile>
36.    <occupation>House servant</occupation>
37.    <birthplace county="KEN">Staple</birthplace>
38.  </customer>


ช่วยแก้errorให้ทีค่ะ ขอบคุณค่ะ

ผลลัพธ์ที่ต้องการ

output



Tag : WebService

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-02-17 23:14:12 By : TheCatzika View : 1532 Reply : 1
 

 

No. 1

Guest


ตอนนี้ทำได้แล้วค่ะ ^^
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-18 18:55:15 By : TheCatzika
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยแก้ error JAVA Webservice ให้หน่อยค่ะ กำลังศึกษาค่ะแต่ไม่ค่อยเข้าใจ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่