Java ???? XML ????????????????????
???????????? ???????[ 2012/8/15 14:31:03 ] ????????
????SAX ??????????????????????????? org.xml.sax ???С??????????? ContentHandler??DTDHandler??EntityResolver ?? ErrorHandler?? ???? ContentHandler ????????????????????????????????????????DTDHandler ?? EntityResolver ???????????? DTD ???????????????????? ErrorHandler ???????????????DefaultHandler ??????????????????????????????????? BookHandler ????? DefaultHandler ?? ???????????е??????????? startDocument()??endDocument()??startElement()??endElement() ?? characters() ??????????????????????
????Digester ???? XML
??????????? XML ???? JavaBean ??????????Apache ???μ??????? Digester ???????????????????????????????? XML ???? JavaBean ?洢????浱?У? ????????????????????????????ж????????????????????????? XML ?????????????????ù????????????????????????????????????
????????????? Digester ???? XML ????????Σ?
// ??????????? XML ??·?????????????????
File input = new File("books.xml");
Digester digester = new Digester();
// ????????? <books> ??????????ó???? test.myBean.Books ??? JavaBean ????????????
digester.addObjectCreate("books"?? "test.myBean.Books");
digester.addSetProperties("books");
// ????????? <books/book> ??????????????? test.myBean.Book ??? JavaBean
digester.addObjectCreate("books/book"?? "test.myBean.Book");
digester.addSetProperties("books/book");
// ??????????????????????? JavaBean ?? addBook() ?????????? <books/book> ????????????
digester.addSetNext("books/book"?? "addBook"?? "test.myBean.Book");
// ?????????????????????????????н?????????
Books books = (Books) digester.parse(input);
???????????????????????? Digester ???? XML ???Щ??????????????Щ????????????? ???????Digester ?????????????? XML ?????????? XML ??????? JavaBean???????? XML ????????????? JavaBean?? ??????? attribute ????? JavaBean ????? Field?????????????????? tag ????????????? tag ???????????μ? XML?????????????μ? JavaBean?? ???????? Field ?????? Bean ???У???????????????????????????? XML ???н?????
??????????
????????????? Java ???? XML ????????ü????????? DOM ?????????????????????????????????????????????????? XML ????? SAX ??????????????????????????ν??? XML ????????????????????????????????????? Digester/JAXB ????????????????????????????е????????????????? API ???????÷????? ???????????????????????????? XML ????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11