Dom Parsing
Lili 18 male leo 20 male chichy 23 female
Xml curd operations
To operate XML, you must first:
Document getDocument () DocumentBuilderFactory factory = DocumentBuilder builder = Document document Document = builder. parse ("src/XML/person. xml "}
Create)
Element element = Element newElement = document.createElement("chinese" element.setAttribute("type", "pepole" }
Update)
NodeList nodeList = document. getElementsByTagName ("chinese" (I = 0; I <nodeList. getLength (); I ++ Node node = Element elment = String id = elment. getAttribute ("id" ("001" NodeList tagList = elment. getElementsByTagName ("name" Node nodeName = tagList. item (0 nodeName. setTextContent ("Li "}
Read)
ReadXML () String result = ""; String id = "" String name = "" String age = "" String gender = "" Document document = NodeList nodeList = document. getElementsByTagName ("chinese" (I = 0; I <nodeList. getLength (); I ++ Node node = Element element = id = element. getAttribute ("id" NodeList childList = (j = 0; j <childList. getLength (); j ++ Node childNode = String childName = ("name" name = ("age" age = ("gender" gender = result + "ID: "+ id +", name: "+ name +", age "+ age +", gender: "+ gender +" \ n "}
Delete operation
NodeList nodeList = document.getElementsByTagName("chinese" ( i = 0; i < nodeList.getLength(); i++ Node node = Element element = String id = element.getAttribute("id" ("001" NodeList childList = ( j = 0; j < childList.getLength(); j++ Node childNode = ("name" Element childElement = Node pareNode = }
After the operation is complete, you must save:
SaveXML (Document document) TransformerFactory factory = Transformer transFormer = Source xmlSource = Result outputTarget = StreamResult ("src/XML/person. xml "}