Введение
Java API для работы с XML, или JAXP ('/dʒ//æ//k//s//p//iː/ JAKSpee), один из интерфейсов программирования приложений Java XML, предоставляет возможность валидации и разбора XML-документов. Он включает три основных интерфейса разбора:
In computing, the Java API for XML Processing, or JAXP ('/dʒ//æ//k//s//p//iː/ JAKSpee), one of the Java XML Application programming interfaces, provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:
the Document Object Model parsing interface or DOM interface
the Simple API for XML parsing interface or SAX interface
the Streaming API for XML or StAX interface (part of JDK 6; separate jar available for JDK 5)
In addition to the parsing interfaces, the API provides an XSLT interface to provide data and structural transformations on an XML document. JAXP was developed under the Java Community Process as JSR 5 (JAXP 1.0), JSR 63 (JAXP 1.1 and 1.2), and JSR 206 (JAXP 1.3). Java SE version JAXP version bundled 1.4 1.1 1.5 1.3 1.6 1.4 1.7.0 1.4.5 1.7.40 1.5 1.8 1.6
JAXP version 1.4.4 was released on September 3, 2010. JAXP 1.3 was declared end of life on February 12, 2008.
интерфейс разбора Document Object Model, или интерфейс DOM;
интерфейс разбора Simple API for XML, или интерфейс SAX;
интерфейс Streaming API for XML, или интерфейс StAX (часть JDK 6; отдельная JAR-библиотека доступна для JDK 5).
In computing, the Java API for XML Processing, or JAXP ('/dʒ//æ//k//s//p//iː/ JAKSpee), one of the Java XML Application programming interfaces, provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:
the Document Object Model parsing interface or DOM interface
the Simple API for XML parsing interface or SAX interface
the Streaming API for XML or StAX interface (part of JDK 6; separate jar available for JDK 5)
In addition to the parsing interfaces, the API provides an XSLT interface to provide data and structural transformations on an XML document. JAXP was developed under the Java Community Process as JSR 5 (JAXP 1.0), JSR 63 (JAXP 1.1 and 1.2), and JSR 206 (JAXP 1.3). Java SE version JAXP version bundled 1.4 1.1 1.5 1.3 1.6 1.4 1.7.0 1.4.5 1.7.40 1.5 1.8 1.6
JAXP version 1.4.4 was released on September 3, 2010. JAXP 1.3 was declared end of life on February 12, 2008.
В дополнение к интерфейсам разбора, API предоставляет интерфейс XSLT для преобразования данных и структуры XML-документа. JAXP был разработан в рамках Java Community Process как JSR 5 (JAXP 1.0), JSR 63 (JAXP 1.1 и 1.2) и JSR 206 (JAXP 1.3). Соответствие версий Java SE и JAXP: 1.4 – 1.1, 1.5 – 1.3, 1.6 – 1.4, 1.7.0 – 1.4.5, 1.7.40 – 1.5, 1.8 – 1.6.
In computing, the Java API for XML Processing, or JAXP ('/dʒ//æ//k//s//p//iː/ JAKSpee), one of the Java XML Application programming interfaces, provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:
the Document Object Model parsing interface or DOM interface
the Simple API for XML parsing interface or SAX interface
the Streaming API for XML or StAX interface (part of JDK 6; separate jar available for JDK 5)
In addition to the parsing interfaces, the API provides an XSLT interface to provide data and structural transformations on an XML document. JAXP was developed under the Java Community Process as JSR 5 (JAXP 1.0), JSR 63 (JAXP 1.1 and 1.2), and JSR 206 (JAXP 1.3). Java SE version JAXP version bundled 1.4 1.1 1.5 1.3 1.6 1.4 1.7.0 1.4.5 1.7.40 1.5 1.8 1.6
JAXP version 1.4.4 was released on September 3, 2010. JAXP 1.3 was declared end of life on February 12, 2008.
Версия JAXP 1.4.4 была выпущена 3 сентября 2010 года. Поддержка JAXP 1.3 была прекращена 12 февраля 2008 года.
In computing, the Java API for XML Processing, or JAXP ('/dʒ//æ//k//s//p//iː/ JAKSpee), one of the Java XML Application programming interfaces, provides the capability of validating and parsing XML documents. It has three basic parsing interfaces:
the Document Object Model parsing interface or DOM interface
the Simple API for XML parsing interface or SAX interface
the Streaming API for XML or StAX interface (part of JDK 6; separate jar available for JDK 5)
In addition to the parsing interfaces, the API provides an XSLT interface to provide data and structural transformations on an XML document. JAXP was developed under the Java Community Process as JSR 5 (JAXP 1.0), JSR 63 (JAXP 1.1 and 1.2), and JSR 206 (JAXP 1.3). Java SE version JAXP version bundled 1.4 1.1 1.5 1.3 1.6 1.4 1.7.0 1.4.5 1.7.40 1.5 1.8 1.6
JAXP version 1.4.4 was released on September 3, 2010. JAXP 1.3 was declared end of life on February 12, 2008.
Интерфейс SAX
В отличие от DOM-парсера, SAX-парсер не создает в памяти представление XML-документа, поэтому работает быстрее и использует меньше памяти. Вместо этого, SAX-парсер информирует клиентов о структуре XML-документа, вызывая обратные вызовы, то есть, вызывая методы на экземпляре, предоставленном парсеру. Этот способ доступа к документу называется потоковой обработкой XML (Streaming XML). Класс DefaultHandler реализует интерфейсы Locator, DeclHandler, ContentHandler и ErrorHandler. Большинство клиентов будут заинтересованы в методах, определенных в интерфейсе ContentHandler, которые вызываются, когда SAX-парсер обнаруживает соответствующие элементы в XML-документе. Наиболее важными методами в этом интерфейсе являются: startDocument и endDocument – методы, которые вызываются в начале и конце XML-документа; startElement и endElement – методы, которые вызываются в начале и конце элемента документа; characters – метод, который вызывается с текстовыми данными, содержащимися между начальным и конечным тегами элемента XML-документа. Клиенты предоставляют подкласс DefaultHandler, который переопределяет эти методы и обрабатывает данные. Это может включать сохранение данных в базе данных или запись их в поток. В процессе разбора парсеру может потребоваться доступ к внешним документам. Для часто используемых документов можно организовать локальный кэш с помощью каталога XML. Эта функция была представлена в Java 1.3 в мае 2000 года.
and methods that are called at the start and end of a XML document. startElement and endElement methods that are called at the start and end of a document element. characters method that is called with the text data contents contained between the start and end tags of an XML document element. Clients provide a subclass of the DefaultHandler that overrides these methods and processes the data. This may involve storing the data into a database or writing it out to a stream. During parsing, the parser may need to access external documents. It is possible to store a local cache for frequently used documents using an XML Catalog. This was introduced with Java 1.3 in May 2000.
Интерфейс StAX
StAX был разработан как компромисс между DOM и SAX интерфейсами. В его концепции, программной точкой входа является курсор, представляющий позицию в документе. Приложение перемещает курсор вперед, "извлекая" информацию из парсера по мере необходимости. Это отличается от API, основанного на событиях, такого как SAX, который "передает" данные приложению, требуя от приложения поддерживать состояние между событиями для отслеживания текущей позиции в документе.