1. Trang chủ
  2. » Thể loại khác

JAXP(Java API for XML Processing)

3 78 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 3
Dung lượng 66,11 KB

Nội dung

Section 4 – The Simple API for XML (SAX) Tutorial – XML Programming in Java 16 Section 4 – The Simple API for XML (SAX) The Simple API for XML SAX is an event-driven API for parsing XML documents. In our DOM parsing examples, we sent the XML document to the parser, the parser processed the complete document, then we got a Document object representing our document. In the SAX model, we send our XML document to the parser, and the parser notifies us when certain events happen. It’s up to us to decide what we want to do with those events; if we ignore them, the information in the event is discarded. Sample code Before we go any further, make sure you’ve downloaded our sample XML applications onto your machine. Unzip the file xmljava.zip, and you’re ready to go! (Be sure to remember where you put the file.) SAX events The SAX API defines a number of events. You can write Java code that handles all of the events you care about. If you don’t care about a certain type of event, you don’t have to write any code at all. Just ignore the event, and the parser will discard it. Tutorial – XML Programming in Java Section 4 – The Simple API for XML (SAX) 17 A wee listing of SAX events We’ll list most of the SAX events here and on the next panel. All of the events on this panel are commonly used; the events on the next panel are more esoteric. They’re part of the HandlerBase class in the org.xml.sax package. • startDocument Signals the start of the document. • endDocument Signals the end of the document. • startElement Signals the start of an element. The parser fires this event when all of the contents of the opening tag have been processed. That includes the name of the tag and any attributes it might have. • endElement Signals the end of an element. • characters Contains character data, similar to a DOM Text node. More SAX events Here are some other SAX events: • ignorableWhitespace This event is analogous to the useless DOM nodes we discussed earlier. One benefit of this event is that it’s different from the character event; if you don’t care about whitespace, you can ignore all whitespace nodes by ignoring this event. • warning, error, and fatalError These three events indicate parsing errors. You can respond to them as you wish. • setDocumentLocator The parser sends you this event to allow you to store a SAX Locator object. The Locator object can be used to find out exactly where in the document an event occurred. Section 4 – The Simple API for XML (SAX) Tutorial – XML Programming in Java 18 A note about SAX interfaces The SAX API actually defines four interfaces for handling events: EntityHandler, DTDHandler, DocumentHandler, and ErrorHandler. All of these interfaces are implemented by HandlerBase. Most of the time, your Java code will extend the HandlerBase class. If you want to subdivide the functions of your code (maybe you’ve got a great DTDHandler class already written), you can implement the xxxHandler classes individually. <?xml version="1.0"?> <sonnet type="Shakespearean"> <author> <last-name>Shakespeare</last-name> <first-name>William</first-name> <nationality>British</nationality> <year-of-birth>1564< JAXP(Java API for XML Processing) JAXP(Java API for XML Processing) Bởi: Wiki Pedia Java API for XML Processing, hay JAXP, API cho lập trình Java XML Nó cung cấp khả kiểm chứng phân tích tài liệu XML Hai loại giao diện (interface) để phân tích là: • Giao diện phân tích dạng Mô hình đối tượng tài liệu (Document Object Model) - viết tắt DOM • Giao diện phân tích API đơn giản dành cho XML (Simple API for XML) - viết tắt SAX Giao diện thứ ba, với hứa hẹn thêm vào xuất lớn tới Java (tên hiệu Mustang), dự kiến vào cuối năm 2006 là: • StAX, API dẫn luồng cho XML (the Streaming API for XML) JSR #173 Cùng với giao diện phân tích, API cung cấp giao diện XSLT để cung cấp việc chuyển đổi liệu cấu trúc từ tài liệu XML sang dạng khác J2SE 1.4 JDK phiên mà có kèm theo JAXP 1.1 Giao diện DOM Giao diện DOM có lẽ giao diện dễ hiểu Nó phân tích toàn tài liệu XML kiến thiết cấu trúc hoàn chỉnh đại diện cho tài liệu, nhớ, cách dùng lớp để mô hình hóa khái niệm ghi Tài liệu chi tiết đặc tả kĩ thuật Document Object Model(DOM) Cấp độ Bộ phân tích DOM gọi DocumentBuilder, tạo nên hình thức đại diện cho Document nhớ javax.xml.parsers.DocumentBuilder tạo nên javax.xml.parsers.DocumentBuilderFactory DocumentBuilder tạo trường hợp org.w3c.dom.Document, tức cấu trúc chứa nốt Tài liệu XML Mỗi nốt cấu trúc thực giao diện org.w3c.dom.Node Có nhiều loại 1/3 JAXP(Java API for XML Processing) nốt đại diện cho loại liệu tìm thấy tài liệu XML Loại nốt quan trọng là: • Nốt phần tử Loại có thuộc tính nằm bên • Nốt văn Loại đại diện cho phần văn nằm thẻ mở thẻ đóng phần tử tài liệu Xem tài liệu javadoc gói org.w3c.dom để có danh sách đầy đủ loại nốt Ví dụ java.io.File file = new java.io.File("c:/news.xml"); javax.xml.parsers.DocumentBuilderFactory DocumentBuilderFactory.newInstance(); dbf = javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc=null; if (file.exists()){ doc = db.parse(file); } if (doc != null) { /* xử lí */ NodeList nodes = doc.getElementsByTagName("content"); for (int i = 0; i < nodes.getLength(); i++) { Element e = (Element) nodes.item(i); /* xử lí */ } } 2/3 JAXP(Java API for XML Processing) Giao diện SAX Bộ phân tích SAX gọi SAXParser tạo javax.xml.parsers.SAXParserFactory Khác với phân tích DOM, SAXParser không tạo hình thức đại diện tài liệu XML nhớ hoạt động nhanh hơn, tốn nhớ Thay vào đó, phân tích SAXParser thông báo cho trình khách cấu trúc tài liệu XML cách gọi hàm callbacks, nghĩa là, cách gọi phương pháp trường hợp Bản mẫu:Javadoc:SE cung cấp cho phân tích Lớp DefaultHandler nằm gói org.xml.sax.helpers Lớp thực giao diện ContentHandler, ErrorHandler, DTDHandler, EntityResolver Đại phận trình khách quan tâm đến phương pháp định nghĩa giao diện ContentHandler mà Các phương pháp giao diện ContentHandler, DefaultHandler thực hiện, gọi đến phân tích SAX bắt gặp phần tử tương ứng tài liệu XML Những phương pháp chủ yếu giao diện bao gồm: • phương pháp startDocument() endDocument() Những phương pháp gọi lúc mở đầu kết thúc tài liệu XML • phương pháp characters() Phương pháp gọi với nội dung văn thẻ mở thẻ đóng phần tử tài liệu XML Các trình khách cung cấp phân lớp DefaultHandler Phân lớp sử dụng để lấn quyền phương pháp xử lý liệu Quá trình bao gồm việc lưu trữ liệu vào sở liệu, viết chúng luồng (dữ liệu) Giao diện XSLT Ngôn ngữ tập tin định dạng XML dành cho việc chuyển đổi - (The XML Stylesheet Language for Transformations, hay XSLT) cho phép biến đổi tài liệu XML sang dạng thức liệu khác 3/3 Working with XML Top Contents Index Glossary Working with XML The Java API for Xml Parsing (JAXP) Tutorial by Eric Armstrong [Version 1.1, Update 31 -- 21 Aug 2001] This tutorial covers the following topics: Part I: Understanding XML and the Java XML APIs explains the basics of XML and gives you a guide to the acronyms associated with it. It also provides an overview of the Java TM XML APIs you can use to manipulate XML-based data, including the Java API for XML Parsing ((JAXP). To focus on XML with a minimum of programming, follow The XML Thread, below. Part II: Serial Access with the Simple API for XML (SAX) tells you how to read an XML file sequentially, and walks you through the callbacks the parser makes to event-handling methods you supply. Part III: XML and the Document Object Model (DOM) explains the structure of DOM, shows how to use it in a JTree, and shows how to create a hierarchy of objects from an XML document so you can randomly access it and modify its contents. This is also the API you use to write an XML file after creating a tree of objects in memory. Part IV: Using XSLT shows how the XSL transformation package can be used to write out a DOM as XML, convert arbitrary data to XML by creating a SAX parser, and convert XML data into a different format. Additional Information contains a description of the character encoding schemes used in the Java platform and pointers to any other information that is relevant to, but outside the scope of, this tutorial. http://java.sun.com/xml/jaxp-1.1/docs/tutorial/index.html (1 of 2) [8/22/2001 12:51:28 PM] Working with XML The XML Thread Scattered throughout the tutorial there are a number of sections devoted more to explaining the basics of XML than to programming exercises. They are listed here so as to form an XML thread you can follow without covering the entire programming tutorial: ● A Quick Introduction to XML ● Writing a Simple XML File ● Substituting and Inserting Text ● Defining a Document Type ● Defining Attributes and Entities ● Referencing Binary Entities ● Defining Parameter Entities ● Designing an XML Document Top Contents Index Glossary http://java.sun.com/xml/jaxp-1.1/docs/tutorial/index.html (2 of 2) [8/22/2001 12:51:28 PM] Understanding XML and the Java XML APIs Top Contents Index Glossary Part I. Understanding XML and the Java XML APIs This section describes the Extensible Markup Language (XML), its related specifications, and the APIs for manipulating XML files. It contains the following files: What You'll Learn This section of the tutorial covers the following topics: 1. A Quick Introduction to XML shows you how an XML file is structured and gives you some ideas about how to use XML. 2. XML and Related Specs: Digesting the Alphabet Soup helps you wade through the acronyms surrounding the XML standard. 3. An Overview of the APIs gives you a high-level view of the JAXP and associated APIs. 4. Designing an XML Data Structure gives you design tips you can use when setting up an XML data structure. Top Contents Index Glossary http://java.sun.com/xml/jaxp-1.1/docs/tutorial/overview/index.html [8/22/2001 12:51:30 PM] 1. A Quick Introduction to XML Top Contents Index Glossary 1. A Quick Introduction to XML Link Summary Local Links ● XML and Last Revised: 2/00 (cac) INTRODUCTION TO USING DRAGON NATURALLY SPEAKING FOR WORD PROCESSING Last Revised: 2/00 (cac) NaturallySpeaking Student Manual Table of Contents Page i Dragon Naturally Speaking Student Manual INTRODUCTION • These handouts were created to provide the new Dragon Naturally Speaking user with critical information about how Naturally Speaking works. • These handouts apply to Naturally Speaking and Natural Word. OPENING DRAGON NATURALLY SPEAKING 1 METHOD A: USING KEYBOARD COMMANDS:____________________________1 METHOD B: USING THE MOUSE: ______________________________________2 Long Version .2 Short Version 2 TURNING NATURALLY SPEAKING ON AND OFF .3 OPENING NATURAL WORD 4 METHOD A: USING KEYBOARD COMMANDS:____________________________4 METHOD B: USING THE MOUSE: ______________________________________5 FEEDBACK FROM NATURALLY SPEAKING 6 CREATING A NEW FILE .7 OPENING A FILE THAT HAS BEEN SAVED ON YOUR DISK .8 SAVING NEW DOCUMENT FILES 9 SAVING CHANGES TO OLD DOCUMENT FILES .9 PRINTING A FILE 10 EXITING .11 CORRECTING TEXT 12 CORRECTING NATSPEAK’S MISTAKES________________________________12 CORRECTING YOUR MISTAKES______________________________________12 CORRECTING DICTATED TEXT IN CORRECTION DIALOGUE BOX __________13 CORRECTING COMMANDS__________________________________________14 Correcting Fourteen Special Dictation Commands .14 All Other Commands .14 SCRATCH THAT ___________________________________________________15 UNDO____________________________________________________________15 RESUME WITH ____________________________________________________15 FREQUENTLY USED NAVIGATION COMMANDS 16 SUMMARY OF NAVIGATION COMMANDS 17 Word Table Navigation Commands _____________________________________17 Last Revised: 2/00 (cac) NaturallySpeaking Student Manual Table of Contents Page ii CAPITALIZATION .18 INSERTING TEXT .19 DELETING TEXT .20 STARTING NEW LINES AND PARAGRAPHS .21 SELECTING TEXT 22 EXAMPLES OF SELECTION COMMANDS_______________________________22 SELECTING AND REDICTATING ______________________________________22 SUMMARY OF SELECTION COMMANDS _______________________________22 SELECT AGAIN ____________________________________________________22 CUT, COPY AND PASTE .23 PLAYBACK FEATURE (Listening to Your Voice) 24 READ THAT FEATURE (Listening to the Text in Your Document) .24 BOLD FACING TEXT .25 REMOVING THE BOLD FEATURE 80/IRU;0/6FKHPD0DSSLQJ 6SHFLILFDWLRQ  Grady Booch (Rational Software Corp.) Magnus Christerson (Rational Software Corp.) Matthew Fuchs (CommerceOne Inc.) Jari Koistinen (CommerceOne Inc.) 1. Introduction 1 1.1 XML Schema and UML 2 1.2 Design Center and Fundamental Issues . 2 2. Mapping Overview .2 3. Detailed Mapping and Example . 3 1.3 Introduction 3 1.4 Defining a datatype . 3 1.5 Defining an Element type 4 1.6 Library of Pre-defined element and datatype 5 1.7 Namespaces, versions etc. . 5 4. A Larger Example . 6 1.8 Introduction 6 1.9 The XML Schema . 6 1.10 The Corresponding UML Schema Diagram . 7 5. References 7 Abstract This paper describes a graphical notation in UML for designing XML Schemas. UML (Unified Modeling Language) is a standard object-oriented design language that has gained virtually global acceptance among both tool vendors as well as software developers. UML has been standardized by the Object Management Group (OMG). XML Schema is an emerging standard from W3C. XML Schema is a language for defining the structure of XML document instances that belong to a specific document type. XML Schema can be seen as replacing the XML DTD syntax. XML Schema provides strong data typing, modularization and reuse mechanisms not available in XML DTDs. There is currently no W3C recommendation for XML Schema, although several have been proposed and W3C is actively working on producing a recommendation. This paper describes the relationship between UML and the SOX schema used by CommerceOne. Our intention is, however, to adapt the mapping to the W3C recommendation when that becomes available. W3C discussions up to this point indicate the notation described here will be upward compatible with the eventual recommendation.  , 1752'8&7,21 XML is rapidly establishing itself as the metagrammar for interorganizational communication around the Internet. It is becoming increasingly urgent that business analysts, systems analysts, and software developers be able to: • model the information to be represented in XML. • describe the relationships between the XML and the systems to process it. Having done so, they must also be able to rapidly generate the boilerplate code associated with implementing these processes. At present there is no tool or tool suite capable of doing this. One path to development is to exploit existing tools using UML to facilitate this. The first step towards doing so is providing a semantically rich mapping from XML into UML. The goal of this paper is to layout such a mapping through XML Schema, a schema language for object-oriented XML. This paper itself does not provide all the information for an end-to-end mapping from UML to XML Schema to programming language-specific data structures, but but such a mapping can be built on the information presented here. Hindawi Publishing Corporation EURASIP Journal on Embedded Systems Volume 2008, Article ID 163864, 6 pages doi:10.1155/2008/163864 Research Article Embedded XML DOM Parser: An Approach for XML Data Processing on Networked Embedded Systems with Real-Time Requirements Esther M ´ ınguez Collado, 1 M. Angeles Cavia Soto, 2 Jos ´ eA.P ´ erez Garc ´ ıa, 3 Iv ´ an M. Delamer, 1 and Jose L. Mart ´ ınez Lastra 1 1 Institute of Production Engineering, Tampere University of Technology, 33101 Tampere, Finland 2 Depart amento de Ingenieria Elect rica y Energetica, Universidad de Cantabria, 39005 Santander, Spain 3 E.T.S. de Ingenieria Industrial, Univerisdad de Vigo, 36310 Vigo, Spain Correspondence should be addressed to Jose L. Mart ´ ınez Lastra, lastra@ieee.org Received 5 February 2007; Revised 18 June 2007; Accepted 8 October 2007 Recommended by Valeriy Vyatkin Trends in control and automation show an increase in data processing and communication in embedded automation controllers. The eXtensible Markup Language (XML) is emerging as a dominant data syntax, fostering interoperability, yet little is still known about how to provide predictable real-time performance in XML processing, as required in the domain of industrial automation. This paper presents an XML processor that is designed with such real-time performance in mind. The publication attempts to disclose insight gained in applying techniques such as object pooling and reuse, and other methods targeted at avoiding dynamic memory allocation and its consequent memory fragmentation. Benchmarking tests are reported in order to illustrate the benefits of the approach. Copyright © 2008 Esther M ´ ınguez Collado et al. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. 1. INTRODUCTION Current trends in the industrial automation domain are pushing the adoption of information and communica- tion technologies (ICT) at the device level, increasing the amount of information processing local to where process control occurs. Networked embedded systems (NES) are be- ing equipped with increasing computation power and com- munication resources that allow direct integration with en- terprise and supervisory control systems. Among the tech- nologies that are used to represent and communicate infor- mation, the eXtensible Markup Language (XML) is emerg- ing as a prevailing syntax in the embedded domain, answer- ing to requirements of interoperability and integration with desktop and server-type systems. A few example technolo- gies that illustrate this trend are the OPC Unified Architec- ture (OPC-UA) [1], the Computer Aided Manufacturing us- ing XML (CAMX) framework [2], and the Devices Profile for Web Se r vices ( DPWS) [3]. One of the challenges faced by the processing of XML data in embedded automation controllers is the fulfillment of real-time requirements. The majority of currently available off-the-shelf XML processors do not provide features that ad- dress deterministic behavior, and background research pre- sented in Section 2 has found no available embedded XML processor or research activities pointing in this direction. In addition, the volume of data exchange and data processing within industrial controllers is increasing, taking more re- sources which were previously just granted to control tasks without need for arbitration. The challenge is therefore to provide a predictable behavior for XML processing activities so that the performance of real-time control tasks is not af- .. .JAXP(Java API for XML Processing) nốt đại diện cho loại liệu tìm thấy tài liệu XML Loại nốt quan trọng là: • Nốt phần tử Loại có thuộc... doc.getElementsByTagName("content"); for (int i = 0; i < nodes.getLength(); i++) { Element e = (Element) nodes.item(i); /* xử lí */ } } 2/3 JAXP(Java API for XML Processing) Giao diện SAX Bộ phân... diện XSLT Ngôn ngữ tập tin định dạng XML dành cho việc chuyển đổi - (The XML Stylesheet Language for Transformations, hay XSLT) cho phép biến đổi tài liệu XML sang dạng thức liệu khác 3/3

Ngày đăng: 30/10/2017, 20:40

TỪ KHÓA LIÊN QUAN