In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to use the xml file as a database for students to add, delete, change and search, I believe that many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1.xml file:
Ttt 44 linda2 22 linda3 23 jack 2 yyh2 22
2.Java code
Import java.io.File;import java.io.IOException;import java.util.Scanner;import javax.xml.parsers.ParserConfigurationException;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerConfigurationException;import javax.xml.transform.TransformerException;import javax.xml.transform.TransformerFactory;import javax.xml.transform.TransformerFactoryConfigurationError;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList Import org.w3c.dom.Text;import org.xml.sax.SAXException;// in the student management system, the student's student number is unique, the name may repeat public class StudentManager {public static void main (String [] args) {try {Document doc = Domutils.getDoc ("relative path to the xml file"); Scanner input = new Scanner (System.in) System.out.println ("Welcome to the student management system\ n\ n\ nPlease enter what you want to do:\ N1. Add student information\ n2. Delete student information\ n3. Modify student information\ n (please enter the previous serial number) "); int num = input.nextInt (); if (num = = 1) {addStudent (doc);} else if (num = = 2) {delStudent (doc);} else if (num = = 3) {updStudent (doc);}} catch (SAXException e) {e.printStackTrace () } catch (IOException e) {e.printStackTrace ();} catch (ParserConfigurationException e) {e.printStackTrace ();}} / / modify student information private static void updStudent (Document doc) {Element updStudent = null; Scanner input = new Scanner (System.in); System.out.println ("Please enter the student number you want to modify:"); String studentid = input.nextLine () System.out.println ("Please enter the name of the new student:"); String newName = input.nextLine (); System.out.println ("Please enter the age of the new student:"); String newAge = input.nextLine (); / / list each student, and the for loop determines which student you want to modify the information is NodeList list = doc.getElementsByTagName ("student"); for (int I = 0; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.