Good tool for XML file processing - read data --cnjsp.org

xiaoxiao2021-03-06  84

http://www.cnjbb.org/thread.jsp?boardid=46&threadid=43597&pageno=1&perpage=10&mode=block here will make you more quickly learn Java! Not only give a good tutorial, but also have Java cattle to give you Develop plans and answer questions! Cnjsp.org is very good! This article introduces a good tool for XML processing, let everyone sneak a sneak peek ----- jdom. The following is simply introduced below. (1) Do you know two basic methods for processing XML files: DOM; SAX. (2) JDOM is not Developers need to know how to build these two parsers; JDom has set it out for you. (3) Simple usage is as follows: Toyota Celica 1997 green 1abc234 Save this file in c: /car.xml Now we have to read the data: (1) Generate the parser and create a Document Document Object Saxbuilder Builder = New Saxbuilder (); Document Doc = Builder.Builder (New file ("c: /car.xml")); (2) JDOM puts the VIN in as attribute in <> start and ; Toyota in Toyota is called Text (Content). Element root = doc.getrootElement (); string vin = root.getattributevalue ("VIN"); // Output: 123 element make = root. Getchild ("make"); // If there is the same label, list list = root.getchildren ("label name"); string make_text = make.getText (); // Out: Toyota (3) To get another label Data, as above. (4) Test code: import org.jdom. *; Public class test {public static void main (string arg []) {Try {saxbuilder builder = n EW saxbuilder (); docuument doc = builder.build (new file ("c: /car.xml"); element root = doc.getrootElement (); string vin = root.getattributevalue ("vin"); // Output : 123 System.out.println (VIN); Element make = root.getchild ("make"); // If there is the same tag, list list = root.getchildren ("label name");

转载请注明原文地址:https://www.9cbs.com/read-95336.html

New Post(0)