140 likes | 345 Views
声明. 本课件仅用于北京航空航天大学计算机学院的教学; 本课件修改采用了一些网络资源(论文、研究报告、技术报告等),在采用的时候并没有准确标注引用信息。. 应用程序接口 API. JAXP: Java API for XML Processing JAXB: Java Architecture for XML Binding JDOM: Java DOM DOM4J: an alternative to JDOM. JAXP 1.1. Java Community Process initiative JSR-000063
E N D
声明 • 本课件仅用于北京航空航天大学计算机学院的教学; • 本课件修改采用了一些网络资源(论文、研究报告、技术报告等),在采用的时候并没有准确标注引用信息。
应用程序接口API • JAXP: Java API for XML Processing • JAXB: Java Architecture for XML Binding • JDOM: Java DOM • DOM4J: an alternative to JDOM
JAXP 1.1 • Java Community Process initiative JSR-000063 • A thin and lightweight Java API for parsing and transforming XML documents • Allows for pluggable parsers and transformers • Allows parsing of XML document using: • . Event-drive (SAX 2.0) • . Tree based (DOM Level 2) • Allows transforming XML document using: • . XSL and XSLT • JAXP Specification 1.1 • . http://java.sun.com/Download4
SAX.Simple API for XML • Parsing • Reading and well-formed'ness checking and validating • Event-driven Parser • . You provide the event Handler • . Sequential read access only => one-time access • Fast and Lightweight • . Documents does not have to be entirely in memory • . Does not support modification of document • Started as a Community-driven project • . Org.xml.sax • SAX is free!
SAX Example • <?xml version="1.0"?> • <doc> • <para>Hello, world!</para> • </doc> • An event-based interface will break the structure of this document down into a series of linear events: • start document • start element: doc • start element: para • characters: Hello, world! • end element: para • end element: doc • end document
DOM: Document Object Model • The Document Object Model (DOM) is an application programming interface (API) for processing well-formed and valid XML documents • " It defines the logical structure of documents and the way a document is accessed and manipulated • " With the Document Object Model, programmers can build documents, navigate their structure, and add, modify, or delete elements and content
DOM Example:Example table, taken from an HTML document • <TABLE> • <TBODY> • <TR> • <TD>Shady Grove</TD> • <TD>Aeolian</TD> • </TR> • <TR> • <TD>Over the River, Charlie</TD> • <TD>Dorian</TD> • </TR> • </TBODY> • </TABLE>
JAXB • Java Architecture for XML Binding • " JAXB provides a fast and convenient way to create a two-way mapping between XML documents and Java objects • " WARNING: Significant changes could occur between the current working draft and the final 1.0 specification
Motivations of JAXB • SAX and DOM • . Too low-level APIs • " Requires XML knowledge • . Hard to program • " You have to build your high-level Java objects yourself • . Hard to maintain • " Schema change forces reprogramming • . Forces a lot of coding • " Need for APIs that provide higher-level abstraction
XML Binding.What Is It? • Map components of an XML document to in-memory objects • " Object should represent intended meaning of document according to its schema • " What should the classes be? • " Some cases obvious: String, Date, Vector. • " In general, classes should be generated directly from the schema, i.e.: • . A Java. technology-level binding of the schema