Bình luận
|
Trần Việt Đức Anh [C2010L]
2021-09-18 10:39:42
|
#Info.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- DTD -->
<!DOCTYPE info [
<!ELEMENT info (fullname, gender, email, cellphone, hobby, programming_language, equipment)>
<!ELEMENT fullname (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT cellphone (#PCDATA)>
<!ELEMENT hobby (#PCDATA)>
<!ELEMENT programming_language (#PCDATA)>
<!ELEMENT equipment (#PCDATA)>
<!ENTITY program "Python, ...">
]>
<info>
<fullname>Tran Viet Duc Anh</fullname>
<gender>Male</gender>
<email>ge1362001@gmail.com</email>
<cellphone>0835840067</cellphone>
<hobby>Program, Game, Food</hobby>
<programming_language>C#, &program;</programming_language>
<equipment>Laptop, Cellphone</equipment>
</info>
|
Đào Mạnh Dũng [C2010L]
2021-09-16 14:42:23
|
#profile.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- DTD -->
<!DOCTYPE profile [
<!ELEMENT profile (fullname, gender, email, phone-number, learning-tools, hobby, programming-language)>
<!ELEMENT fullname (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT phone-number (#PCDATA)>
<!ELEMENT learning-tools (#PCDATA)>
<!ELEMENT hobby (#PCDATA)>
<!ELEMENT programming-language (#PCDATA)>
]>
<profile >
<fullname>Đào Mạnh Dũng</fullname>
<gender>Nam</gender>
<email>interface.daodung@gmail.com</email>
<phone-number>0329326246</phone-number>
<learning-tools>Laptop</learning-tools>
<hobby>Code</hobby>
<programming-language>java</programming-language>
</profile >
|
Võ Như Việt [C2010L]
2021-09-16 14:23:56
|
#profile.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- DTD -->
<!DOCTYPE presonal-list [
<!ELEMENT presonal-list (presonal) >
<!ELEMENT presonal (fullname, gender, email, phone-number, interests, learning-devices, programming-language) >
<!ELEMENT fullname (#PCDATA) >
<!ELEMENT gender (#PCDATA) >
<!ELEMENT email (#PCDATA) >
<!ELEMENT phone-number (#PCDATA) >
<!ELEMENT interests (#PCDATA) >
<!ELEMENT learning-devices (#PCDATA) >
<!ELEMENT programming-language (#PCDATA) >
]>
<presonal-list>
<presonal>
<fullname>Vo Nhu Viet</fullname>
<gender>Nam</gender>
<email>viet.vo@gmail.com</email>
<phone-number>0375199293</phone-number>
<interests>Game</interests>
<learning-devices>Laptop</learning-devices>
<programming-language>Java Core</programming-language>
</presonal>
</presonal-list>
|
Phạm Đăng Khoa [community,C2010L]
2021-09-16 14:05:03
|
<?xml version="1.0" encoding="UTF-8"?>
<class>
<className>C2010L</className>
<address>54 Le Thanh Nghi</address>
<student-list>
<student>
<fullname title="0150">Pham Dang Khoa</fullname>
<gender>Male</gender>
<email>khoa.pd.235@gmail.com</email>
<phone-number>0359935310</phone-number>
<address>Vinh Phuc</address>
<interests>Play game</interests>
<tool-learning>PC</tool-learning>
<develop-language>Java Script,php,v.v</develop-language>
</student>
</student-list>
</class>
|
Nguyễn Tiến Đạt [T2008A]
2021-04-08 16:50:26
|
#Interest.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Java2.lesson8.PersonalAnalyse;
import java.util.ArrayList;
/**
*
* @author MyPC
*/
public class Interest {
String sport, game;
ArrayList<String> music = new ArrayList<>();
public Interest() {
}
public String getSport() {
return sport;
}
public void setSport(String sport) {
this.sport = sport;
}
public String getGame() {
return game;
}
public void setGame(String game) {
this.game = game;
}
public ArrayList<String> getMusic() {
return music;
}
public void setMusic(String music1) {
this.music.add(music1);
}
@Override
public String toString() {
return "sport=" + sport + ", game=" + game + ", music=" + music;
}
}
#LearningEquipment.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Java2.lesson8.PersonalAnalyse;
import java.util.ArrayList;
/**
*
* @author MyPC
*/
public class LearningEquipment {
String laptop;
ArrayList<String> bookList = new ArrayList<>();
public LearningEquipment() {
}
public String getLaptop() {
return laptop;
}
public void setLaptop(String laptop) {
this.laptop = laptop;
}
public ArrayList<String> getBookList() {
return bookList;
}
public void setBookList(String book) {
this.bookList.add(book);
}
@Override
public String toString() {
return "laptop=" + laptop + ", bookList=" + bookList;
}
}
#Main.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Java2.lesson8.PersonalAnalyse;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
/**
*
* @author MyPC
*/
public class Main {
public static void main(String[] args) {
Personal person;
try {
File file = new File("thongtincanhan.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
PersonalParser personalParser = new PersonalParser();
parser.parse(file, personalParser);
person = personalParser.person;
System.out.println(person);
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
#Personal.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Java2.lesson8.PersonalAnalyse;
import java.util.ArrayList;
/**
*
* @author MyPC
*/
public class Personal {
String name, gender, birthday, status;
ArrayList<Interest> interestList = new ArrayList<>();
String programLanguage;
ArrayList<LearningEquipment> equipmentList = new ArrayList<>();
public Personal() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public ArrayList<Interest> getInterestList() {
return interestList;
}
public void setInterestList(ArrayList<Interest> interestList) {
this.interestList = interestList;
}
public String getProgramLanguage() {
return programLanguage;
}
public void setProgramLanguage(String programLanguage) {
this.programLanguage = programLanguage;
}
public ArrayList<LearningEquipment> getEquipmentList() {
return equipmentList;
}
public void setEquipmentList(ArrayList<LearningEquipment> equipmentList) {
this.equipmentList = equipmentList;
}
@Override
public String toString() {
return "Personal{" + "name=" + name + ", gender=" + gender + ", birthday=" + birthday + ", status=" + status + ", interestList=" + interestList + ", programLanguage=" + programLanguage + ", equipmentList=" + equipmentList + '}';
}
}
#PersonalParser.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Java2.lesson8.PersonalAnalyse;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
*
* @author MyPC
*/
public class PersonalParser extends DefaultHandler{
Personal person = null;
Interest interest = new Interest();
LearningEquipment equipment = new LearningEquipment();
boolean isProfile = false;
boolean isName = false;
boolean isGender = false;
boolean isBirthday = false;
boolean isStatus = false;
boolean isInterest = false;
boolean isSport = false;
boolean isGame = false;
boolean isMusic = false;
boolean isUSUK = false;
boolean isVPOP = false;
boolean isLanguage = false;
boolean isEquipment = false;
boolean isLaptop = false;
boolean isName1 = false;
boolean isBookList = false;
boolean isBook = false;
int check = 0;
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if(qName.equalsIgnoreCase("profile")){
person = new Personal();
isProfile = true;
}
if(isProfile){
if(qName.equalsIgnoreCase("name") && check == 0){
isName = true;
check = 1;
}else if(qName.equalsIgnoreCase("gender")){
isGender = true;
}else if(qName.equalsIgnoreCase("birthday")){
isBirthday = true;
}else if(qName.equalsIgnoreCase("status")){
isStatus = true;
}else if(qName.equalsIgnoreCase("interest")){
isInterest = true;
}else if(qName.equalsIgnoreCase("program-language")){
isLanguage = true;
}else if(qName.equalsIgnoreCase("learning-equipment")){
isEquipment = true;
}
if(isInterest){
if(qName.equalsIgnoreCase("sport")){
isSport = true;
}else if(qName.equalsIgnoreCase("game")){
isGame = true;
}else if(qName.equalsIgnoreCase("music")){
isMusic = true;
}
}
if(isMusic){
if(qName.equalsIgnoreCase("us-uk")){
isUSUK = true;
}else if(qName.equalsIgnoreCase("v-pop")){
isVPOP = true;
}
}
if(isEquipment){
if(qName.equalsIgnoreCase("laptop")){
isLaptop = true;
}else if(qName.equalsIgnoreCase("book-list")){
isBookList = true;
}
}
if(isLaptop){
if(qName.equalsIgnoreCase("name")){
isName1 = true;
}
}
if(isBookList){
if(qName.equalsIgnoreCase("book")){
isBook = true;
}
}
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if(qName.equalsIgnoreCase("profile")){
isProfile = false;
person.interestList.add(interest);
person.equipmentList.add(equipment);
}
if(isProfile){
if(qName.equalsIgnoreCase("name")){
isName = false;
}else if(qName.equalsIgnoreCase("gender")){
isGender = false;
}else if(qName.equalsIgnoreCase("birthday")){
isBirthday = false;
}else if(qName.equalsIgnoreCase("status")){
isStatus = false;
}else if(qName.equalsIgnoreCase("interest")){
isInterest = false;
}else if(qName.equalsIgnoreCase("program-language")){
isLanguage = false;
}else if(qName.equalsIgnoreCase("learning-equipment")){
isEquipment = false;
}
if(isInterest){
if(qName.equalsIgnoreCase("sport")){
isSport = false;
}else if(qName.equalsIgnoreCase("game")){
isGame = false;
}else if(qName.equalsIgnoreCase("music")){
isMusic = false;
}
}
if(isMusic){
if(qName.equalsIgnoreCase("us-uk")){
isUSUK = false;
}else if(qName.equalsIgnoreCase("v-pop")){
isVPOP = false;
}
}
if(isEquipment){
if(qName.equalsIgnoreCase("laptop")){
isLaptop = false;
}else if(qName.equalsIgnoreCase("book-list")){
isBookList = false;
}
}
if(isLaptop){
if(qName.equalsIgnoreCase("name")){
isName1 = false;
}
}
if(isBookList){
if(qName.equalsIgnoreCase("book")){
isBook = false;
}
}
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
String str = String.valueOf(ch, start, length);
if(isProfile){
if(isName){
person.setName(str);
}else if(isGender){
person.setGender(str);
}else if(isBirthday){
person.setBirthday(str);
}else if(isStatus){
person.setStatus(str);
}else if(isInterest){
if(isSport){
interest.setSport(str);
}else if(isGame){
interest.setGame(str);
}else if(isMusic){
if(isUSUK){
interest.setMusic(str);
}else if(isVPOP){
interest.setMusic(str);
}
}
}else if(isLanguage){
person.setProgramLanguage(str);
}else if(isEquipment){
if(isLaptop){
if(isName1){
equipment.setLaptop(str);
}
}else if(isBookList){
if(isBook){
equipment.setBookList(str);
}
}
}
}
}
}
|
Nguyễn đình quân [T2008A]
2021-04-07 08:59:38
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE USER_LIST [
<!ELEMENT user-list (infor, devices)>
<!ELEMENT infor (fullname, sex, birthday, address, email, phone)>
<!ELEMENT fullname (#PCDATA)>
<!ELEMENT birthday (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT devices (device)>
<!ELEMENT device (name, type, price, manufacturer)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT type (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT manufacturer (#PCDATA)>
<!ENTITY NDQ "NGUYEN DINH QUAN">
]>
<user-list xmlns:abc = "https://www.facebook.com/profile.php?id=100008795161326/abc" xmlns:okok = "https://www.facebook.com/profile.php?id=100008795161326/okok">
<abc:infor okok:title = "Hello World!!!">
<okok:fullname>&NDQ;</okok:fullname>
<abc:sex>nam</abc:sex>
<okok:birthday>22/03/2002</okok:birthday>
<abc:address>52/25/52 duong my dinh, nam tu liem, my dinh 2 ,hanoi</abc:address>
<abc:email>nguyenquan200298@gmail.com</abc:email>
<abc:phone>0366908296</abc:phone>
</abc:infor>
<devices>
<device>
<name>dung cu hoc tap</name>
<name>Dell LATITUDE E5550</name>
<type>Laptop</type>
<name>iPhone Xsm</name>
<type>Smart Phone</type>
</device>
<device>
<name>so thich</name>
<type>game :league legends, Arena of valor, PLAYERUNKNOWN'S BATTLEGROUNDS ,Zing Speed Mobile</type>
<type>phim :blockbuster ,romantic comedy, school</type>
<type>nghe nhac:nhac tre , nhac vang</type>
</device>
<device>
<name>ngon ngu lap trinh ban thich</name>
<type>html , css , bootstrap,js</type>
</device>
</devices>
</user-list>
|
Nguyễn Văn Quang [T1907A]
2020-04-17 11:28:02
|
<?xml version="1.0" encoding="UTF-8"?>
<infomation>
<profile>
<fullname>Nguyen Van Quang</fullname>
<age>18</age>
<email>QuangNVth1907036@fpt.edu.vn</email>
<address>Ha Noi</address>
<phoneNumber>0866674394</phoneNumber>
<height>168cm</height>
<weight>53kg</weight>
<status>Độc thân</status>
<hobbiesList>
<hobbies>Code</hobbies>
<hobbies>Chơi Game</hobbies>
<hobbies>Đá bóng</hobbies>
<hobbies>Xem phim</hobbies>
</hobbiesList>
<toolList>
<tool>PC</tool>
<tool>Laptop</tool>
<tool>IDE</tool>
<tool>w3schools</tool>
</toolList>
<proLanguageList>
<language>HTML,CSS,JS</language>
<language>C,C++</language>
<language>Java</language>
<language>SQL</language>
<language>C#</language>
</proLanguageList>
</profile>
</infomation>
package Information;
import java.io.FileInputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class Main {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("infor.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
ProfileHandler profileHandler = new ProfileHandler();
saxParser.parse(fis, profileHandler);
profileHandler.display();
}
}
package Information;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class ProfileHandler extends DefaultHandler{
List<Profile> ProList = new ArrayList<>();
Profile Pro = null;
boolean isFullname = false;
boolean isAge = false;
boolean isEmail = false;
boolean isAddress = false;
boolean isPhoneNumber = false;
boolean isHeight = false;
boolean isWeight = false;
boolean isStatus = false;
boolean isHobbies = false;
boolean isTools = false;
boolean isLanguage = false;
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase("profile")) {
Pro = new Profile();
} else if (qName.equalsIgnoreCase("Fullname")) {
isFullname = true;
} else if (qName.equalsIgnoreCase("Age")) {
isAge = true;
} else if (qName.equalsIgnoreCase("Email")) {
isEmail = true;
} else if (qName.equalsIgnoreCase("Address")) {
isAddress = true;
} else if (qName.equalsIgnoreCase("PhoneNumber")) {
isPhoneNumber = true;
} else if (qName.equalsIgnoreCase("Height")) {
isHeight = true;
} else if (qName.equalsIgnoreCase("Weight")) {
isWeight = true;
} else if (qName.equalsIgnoreCase("Status")) {
isStatus = true;
} else if (qName.equalsIgnoreCase("Hobbies")) {
isHobbies = true;
} else if (qName.equalsIgnoreCase("tool")) {
isTools = true;
} else if (qName.equalsIgnoreCase("Language")) {
isLanguage = true;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("profile")) {
ProList.add(Pro);
Pro = null;
} else if (qName.equalsIgnoreCase("fullname")) {
isFullname = false;
} else if (qName.equalsIgnoreCase("Age")) {
isAge = false;
} else if (qName.equalsIgnoreCase("Email")) {
isEmail = false;
} else if (qName.equalsIgnoreCase("Address")) {
isAddress = false;
} else if (qName.equalsIgnoreCase("PhoneNumber")) {
isPhoneNumber = false;
} else if (qName.equalsIgnoreCase("Height")) {
isHeight = false;
} else if (qName.equalsIgnoreCase("Weight")) {
isWeight = false;
} else if (qName.equalsIgnoreCase("Status")) {
isStatus = false;
} else if (qName.equalsIgnoreCase("Hobbies")) {
isHobbies = false;
} else if (qName.equalsIgnoreCase("tool")) { // chỗ này nè: 1
isTools = false;
} else if (qName.equalsIgnoreCase("Language")) {
isLanguage = false;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
String value = new String(ch, start, length);
if (isFullname) {
Pro.setFullname(value);
} else if (isAge) {
Pro.setAge(Integer.parseInt(value));
} else if (isEmail) {
Pro.setEmail(value);
} else if (isAddress) {
Pro.setAddress(value);
} else if (isPhoneNumber) {
Pro.setPhonenumber(Integer.parseInt(value));
} else if (isHeight) {
Pro.setHeight(value);
} else if (isWeight) {
Pro.setWeight(value);
} else if (isStatus) {
Pro.setStatus(value);
} else if (isHobbies) {
Pro.getHobbiesList().add(value);
} else if (isTools) {
Pro.getToolList().add(value);
} else if (isLanguage) {
Pro.getProLanguageList().add(value);
}
}
public void display() {
ProList.forEach((profile9) -> {
profile9.display();
});
}
}
package Information;
import java.util.ArrayList;
import java.util.List;
public class Profile {
String fullname,email,address,height,weight,status;
int age,phonenumber;
List<String> toolList = new ArrayList<>();
List<String> hobbiesList = new ArrayList<>();
List<String> proLanguageList = new ArrayList<>();
public Profile() {
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(int phonenumber) {
this.phonenumber = phonenumber;
}
public List<String> getToolList() {
return toolList;
}
public void setToolList(List<String> toolList) {
this.toolList = toolList;
}
public List<String> getHobbiesList() {
return hobbiesList;
}
public void setHobbiesList(List<String> hobbiesList) {
this.hobbiesList = hobbiesList;
}
public List<String> getProLanguageList() {
return proLanguageList;
}
public void setProLanguageList(List<String> proLanguageList) {
this.proLanguageList = proLanguageList;
}
public void display(){
System.out.println(" ->Thong tin ca nhan : ");
System.out.format("Fullname : %s \nEmail : %s \nAddress : %s \nHeight : %s \nWeight : %s \nStatus : %s \nAge: %d \nPhoneNumber : %d",fullname ,email ,address ,height ,weight ,status ,age ,phonenumber);
System.out.println("\n ->Danh sach so thich: ");
hobbiesList.forEach((hobbiesList9) -> {
System.out.println(hobbiesList9 + " ");
});
System.out.println("\n ->Danh sach cong cu : ");
toolList.forEach((toolList9) -> {
System.out.println(toolList9 + " ");
});
System.out.println("\n ->Danh sach ngon ngu lap trinh yeu thich : ");
proLanguageList.forEach((prolanguage9) -> {
System.out.println(prolanguage9 + " ");
});
}
}
|
Nguyễn Văn Quang [T1907A]
2020-04-17 11:24:10
|
<?xml version="1.0" encoding="UTF-8"?>
<infomation>
<profile>
<fullname>Nguyen Van Quang</fullname>
<age>18</age>
<email>QuangNVth1907036@fpt.edu.vn</email>
<address>Ha Noi</address>
<phoneNumber>0866674394</phoneNumber>
<height>168cm</height>
<weight>53kg</weight>
<status>Độc thân</status>
<hobbiesList>
<hobbies>Code</hobbies>
<hobbies>Chơi Game</hobbies>
<hobbies>Đá bóng</hobbies>
<hobbies>Xem phim</hobbies>
</hobbiesList>
<toolList>
<tool>PC</tool>
<tool>Laptop</tool>
<tool>IDE</tool>
<tool>w3schools</tool>
</toolList>
<proLanguageList>
<language>HTML,CSS,JS</language>
<language>C,C++</language>
<language>Java</language>
<language>SQL</language>
<language>C#</language>
</proLanguageList>
</profile>
</infomation>
|
Phí Văn Long [T1907A]
2020-04-17 06:46:44
|
em gửi thiếu XML
<?xml version="1.0" encoding="UTF-8"?>
<infomation>
<profile>
<fullname>Phí Văn Long</fullname>
<age>18</age>
<email>longpvth1907014@fpt.edu.vn</email>
<address>Quảng Ninh</address>
<phoneNumber>0355872001</phoneNumber>
<height>170cm</height>
<weight>65kg</weight>
<status>Độc thân</status>
<hobbiesList>
<hobbies>Code</hobbies>
<hobbies>Chơi Game</hobbies>
<hobbies>Đá bóng</hobbies>
<hobbies>Xem phim</hobbies>
</hobbiesList>
<toolList>
<tool>PC</tool>
<tool>Laptop</tool>
<tool>IDE</tool>
<tool>w3schools</tool>
</toolList>
<proLanguageList>
<language>HTML,CSS,JS</language>
<language>C,C++</language>
<language>Java</language>
<language>SQL</language>
<language>C#</language>
</proLanguageList>
</profile>
</infomation>
|
Đường Thanh Bình [T1907A]
2020-04-16 14:54:07
|
<?xml version="1.0" encoding="UTF-8"?>
<infor>
<object>
<fullname>Duong Thanh Binh</fullname>
<age>18</age>
<address>Ha Noi</address>
<phonenumber>0522697743</phonenumber>
<email>binhdtth1907041@fpt.edu.vn</email>
<hobbies>
<hobbieList>
<hobby>Play game</hobby>
<hobby>Movie</hobby>
</hobbieList>
</hobbies>
<height>175cm</height>
<weight>48kg</weight>
<status>Alone</status>
<tools>
<toolList>
<tool>Laptop</toolList>
</toolList>
<programmingLanguage>
<languageList>
<language>Java</language>
<language>HTML</language>
<language>CSS,Bootstrap</language>
<language>XML</language>
</languageList>
</programmingLanguage>
</object>
</infor>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Information;
import java.io.FileInputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
/**
*
* @author Administrator
*/
public class Main {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("infor.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
ProfileHandler profileHandler = new ProfileHandler();
saxParser.parse(fis, profileHandler);
profileHandler.display();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Information;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
*
* @author Administrator
*/
public class ProfileHandler extends DefaultHandler{
List<Profile> ProList = new ArrayList<>();
Profile Pro = null;
boolean isFullname = false;
boolean isAge = false;
boolean isEmail = false;
boolean isAddress = false;
boolean isPhoneNumber = false;
boolean isHeight = false;
boolean isWeight = false;
boolean isStatus = false;
boolean isHobbies = false;
boolean isTools = false;
boolean isLanguage = false;
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase("profile")) {
Pro = new Profile();
} else if (qName.equalsIgnoreCase("Fullname")) {
isFullname = true;
} else if (qName.equalsIgnoreCase("Age")) {
isAge = true;
} else if (qName.equalsIgnoreCase("Email")) {
isEmail = true;
} else if (qName.equalsIgnoreCase("Address")) {
isAddress = true;
} else if (qName.equalsIgnoreCase("PhoneNumber")) {
isPhoneNumber = true;
} else if (qName.equalsIgnoreCase("Height")) {
isHeight = true;
} else if (qName.equalsIgnoreCase("Weight")) {
isWeight = true;
} else if (qName.equalsIgnoreCase("Status")) {
isStatus = true;
} else if (qName.equalsIgnoreCase("Hobbies")) {
isHobbies = true;
} else if (qName.equalsIgnoreCase("tool")) {
isTools = true;
} else if (qName.equalsIgnoreCase("Language")) {
isLanguage = true;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("profile")) {
ProList.add(Pro);
Pro = null;
} else if (qName.equalsIgnoreCase("fullname")) {
isFullname = false;
} else if (qName.equalsIgnoreCase("Age")) {
isAge = false;
} else if (qName.equalsIgnoreCase("Email")) {
isEmail = false;
} else if (qName.equalsIgnoreCase("Address")) {
isAddress = false;
} else if (qName.equalsIgnoreCase("PhoneNumber")) {
isPhoneNumber = false;
} else if (qName.equalsIgnoreCase("Height")) {
isHeight = false;
} else if (qName.equalsIgnoreCase("Weight")) {
isWeight = false;
} else if (qName.equalsIgnoreCase("Status")) {
isStatus = false;
} else if (qName.equalsIgnoreCase("Hobbies")) {
isHobbies = false;
} else if (qName.equalsIgnoreCase("tool")) { // chỗ này nè: 1
isTools = false;
} else if (qName.equalsIgnoreCase("Language")) {
isLanguage = false;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
String value = new String(ch, start, length);
if (isFullname) {
Pro.setFullname(value);
} else if (isAge) {
Pro.setAge(Integer.parseInt(value));
} else if (isEmail) {
Pro.setEmail(value);
} else if (isAddress) {
Pro.setAddress(value);
} else if (isPhoneNumber) {
Pro.setPhonenumber(Integer.parseInt(value));
} else if (isHeight) {
Pro.setHeight(value);
} else if (isWeight) {
Pro.setWeight(value);
} else if (isStatus) {
Pro.setStatus(value);
} else if (isHobbies) {
Pro.getHobbiesList().add(value);
} else if (isTools) {
Pro.getToolList().add(value);
} else if (isLanguage) {
Pro.getProLanguageList().add(value);
}
}
public void display() {
ProList.forEach((profile9) -> {
profile9.display();
});
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Information;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Administrator
*/
public class Profile {
String fullname,email,address,height,weight,status;
int age,phonenumber;
List<String> toolList = new ArrayList<>();
List<String> hobbiesList = new ArrayList<>();
List<String> proLanguageList = new ArrayList<>();
public Profile() {
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(int phonenumber) {
this.phonenumber = phonenumber;
}
public List<String> getToolList() {
return toolList;
}
public void setToolList(List<String> toolList) {
this.toolList = toolList;
}
public List<String> getHobbiesList() {
return hobbiesList;
}
public void setHobbiesList(List<String> hobbiesList) {
this.hobbiesList = hobbiesList;
}
public List<String> getProLanguageList() {
return proLanguageList;
}
public void setProLanguageList(List<String> proLanguageList) {
this.proLanguageList = proLanguageList;
}
public void display(){
System.out.println(" ->Thong tin ca nhan : ");
System.out.format("Fullname : %s \nEmail : %s \nAddress : %s \nHeight : %s \nWeight : %s \nStatus : %s \nAge: %d \nPhoneNumber : %d",fullname ,email ,address ,height ,weight ,status ,age ,phonenumber);
System.out.println("\n ->Danh sach so thich: ");
hobbiesList.forEach((hobbiesList9) -> {
System.out.println(hobbiesList9 + " ");
});
System.out.println("\n ->Danh sach cong cu : ");
toolList.forEach((toolList9) -> {
System.out.println(toolList9 + " ");
});
System.out.println("\n ->Danh sach ngon ngu lap trinh yeu thich : ");
proLanguageList.forEach((prolanguage9) -> {
System.out.println(prolanguage9 + " ");
});
}
}