- Section 1 – Introduction Tutorial – XML Programming in Java. - Tutorial – XML Programming in Java Section 2 – Parser basics. - Section 2 – Parser basics Tutorial – XML Programming in Java. - You need to move parts of the document around (you might want to sort certain elements, for example). - All of the code we’ll discuss in this tutorial uses standard interfaces. - Resources – XML parsers Java. - Tutorial – XML Programming in Java Section 3 – The Document Object Model (DOM). - Node: The base datatype of the DOM.. - Section 3 – The Document Object Model (DOM) Tutorial – XML Programming in Java. - Document.getDocumentElement() Returns the root element of the document.. - Node.getAttribute(attrName). - java domOne sonnet.xml. - Document Statistics for sonnet.xml:. - case Node.ELEMENT_NODE:. - case Node.TEXT_NODE:. - Section 4 – The Simple API for XML (SAX) Tutorial – XML Programming in Java. - Tutorial – XML Programming in Java Section 4 – The Simple API for XML (SAX). - We’ll list most of the SAX events here and on the next panel. - They’re part of the HandlerBase class in the org.xml.sax package.. - Signals the start of the document.. - Signals the end of the document.. - java saxOne sonnet.xml. - We’ve also. - Section 5 – Advanced parser functions Tutorial – XML Programming in Java. - We’ll take our sample XML document and sort the lines of the sonnet.. - Tutorial – XML Programming in Java Section 5 – Advanced parser functions. - doc.createElement("author");. - doc.appendChild(root);. - getElementsByTagName method to retrieve all of the <line>. - Node.TEXT_NODE). - This code actually should check all of the <line>’s children, because it could contain entity references (say the entity &miss. - node.removeChild(kid);. - import com.sun.xml.parser.Parser;. - com.sun.xml.tree.XmlDocumentBuilder;. - new com.sun.xml.parser.Parser();. - import com.sun.xml.parser.Resolver;. - Appendix – Listings of our samples Tutorial – XML Programming in Java. - sonnet.xml. - Tutorial – XML Programming in Java Appendix – Listings of our samples. - import com.ibm.xml.parsers.*;. - Appendix – Listings of our samples Tutorial – XML Programming in Java if (doc. - System.out.print("<");. - System.out.print(node.getNodeName());. - System.out.print(". - System.out.println(">");. - System.out.print("&");. - System.out.print . - Tutorial – XML Programming in Java Appendix – Listings of our samples case Node.TEXT_NODE:. - System.out.print(node.getNodeValue());. - System.out.print("<?");. - System.out.print(data);. - System.out.print("?>");. - Node.ELEMENT_NODE). - System.out.println();. - System.out.print("</");. - System.out.print('>');. - System.out.println("Usage: java domOne uri");. - System.out.println(". - Sample: java domOne sonnet.xml");. - import com.ibm.xml.parsers.DOMParser;. - Tutorial – XML Programming in Java Appendix – Listings of our samples System.out.println("Total: ". - System.out.println("Usage: java domCounter uri");. - Sample: java domCounter sonnet.xml");. - import org.xml.sax.AttributeList;. - import org.xml.sax.HandlerBase;. - import org.xml.sax.Parser;. - import org.xml.sax.SAXException;. - import org.xml.sax.SAXParseException;. - import org.xml.sax.helpers.ParserFactory;. - import com.ibm.xml.parsers.SAXParser;. - Tutorial – XML Programming in Java Appendix – Listings of our samples System.out.print(data);. - System.out.println("<?xml version gt;");. - System.out.print(name);. - System.out.print(">");. - System.out.print(new String(ch, start, length));. - Appendix – Listings of our samples Tutorial – XML Programming in Java public void warning(SAXParseException ex). - Returns a string of the location. - System.out.println("Usage: java saxOne uri");. - Appendix – Listings of our samples Tutorial – XML Programming in Java parser.parse(uri);. - System.out.println . - System.out.println("DocumentHandler Events:");. - System.out.println("ErrorHandler Events:");. - System.out.println("Usage: java saxCounter uri");. - Sample: java saxCounter sonnet.xml");. - Tutorial – XML Programming in Java Appendix – Listings of our samples System.out.print(". - System.out.print("<![CDATA[");. - System.out.print("]]>");. - System.out.println("Usage: java domBuilder");. - Tutorial – XML Programming in Java Appendix – Listings of our samples line03.appendChild(doc.createTextNode("If snow be white, why then her breasts are dun,"));. - import org.xml.sax.InputSource;. - Appendix – Listings of our samples Tutorial – XML Programming in Java break;. - Appendix – Listings of our samples Tutorial – XML Programming in Java else. - 0) System.out.print(node.getNodeValue());. - Appendix – Listings of our samples Tutorial – XML Programming in Java System.out.println(". - import com.sun.xml.tree.XmlDocumentBuilder;. - Tutorial – XML Programming in Java Appendix – Listings of our samples parser.parse(uri);. - System.out.println("Usage: java domTwo uri");. - Sample: java domTwo sonnet.xml");. - Appendix – Listings of our samples Tutorial – XML Programming in Java System.out.print('. - System.out.println("Usage: java saxTwo uri");
Xem thử không khả dụng, vui lòng xem tại trang nguồn hoặc xem
Tóm tắt