Java & Xml tutorial (1) Introduction

Source: Internet
Author: User
Tags xml attribute
XML is a widely used technology for data transmission and storage. Java provides a variety of APIs to parse XML, such as DOM, SAX, StAX, and JAXB. There are also some other APIs for parsing XML, such as JDOM. The purpose of this tutorial is to explore using different types of APIs to parse XML and learn to use XML to execute some common tasks.

XML is a widely used technology for data transmission and storage. Java provides a variety of APIs to parse XML, such as DOM, SAX, StAX, and JAXB. There are also some other APIs for parsing XML, such as JDOM. The purpose of this tutorial is to explore using different types of APIs to parse XML and learn to use XML to execute some common tasks.

Dom xml parsing

DOM parsing is the simplest method of parsing. XML files are loaded into the memory, and XML can be parsed by traversing Node nodes. DOM parsing is suitable for small files with less content. when the file is large, the parsing speed is very slow and takes up a lot of memory.
Read xml files
This article describes how to use DOM to parse XML files and convert XML content to Java objects.
Generate XML file
This article describes how to convert a Java object to an XML file and store it on a local disk.
Modify an XML file
The DOM parsing mechanism can also be used to modify XML data. This article describes how to use the DOM parsing mechanism to add, delete, modify, and attribute elements.

Sax xml parsing

The Java SAX parsing mechanism provides APIs for parsing XML documents. unlike DOM, the SAX parsing mechanism does not load all XML files into the memory, but reads XML documents in sequence. It is event-based parsing. we need to implement a Custom Handler class and use its callback method to parse XML files. When parsing large files, it is more efficient than the DOM parsing mechanism.
Read XML files
Learn how to create our callback Handler class and read XML content to a List.

StAX XML parsing

The full name of Java StAX is Java Streaming API for XML, which provides specific XML parsing implementation. StAX consists of two sets of APIs: cursor-based APIs and iterator-based APIs.
Use the StAX Iterator API to read XML files
In this tutorial, we will learn how to use StAX iteration to read XML.
Use the StAX Iterator API to generate an XML file
In this tutorial, we will learn how to use the StAX API based on the iterator to generate XML.
Use the StAX Cursor API to read XML files
This article describes how to use the StAX Cursor API to read XML data to Java objects.
Use the StAX Cursor API to generate an XML file
The Java StAX Cursor API is very direct in creating XML and outputting data in it. Create an XMLStreamWriter object and write data to the object.

Jdom xml parsing

JDOM provides excellent APIs to make it easier to read, modify, and generate XML files. It provides a packaging class for you to select the specific implementation from the SAX parsing, DOM parsing, StAX event parsing.
The advantage of using JDOM is that you can switch the parser from SAX and dom stax, and provide a Factory method for client applications to choose implementation.
JDOM reads XML files
In this tutorial, we will learn how to use JDOM to read XML files.
JDOM generates XML files
In this tutorial, we will learn how to use JDOM to write XML files. JDOM Document provides a convenient way to create elements and attributes. The XMLOutputter class can be used to write a Document object to any OutputStream or Writer object.

JAXB

The full name of JAXB is Java Architecture for XML Binding. Using the APIs provided by JAXB, you can easily convert Java objects to XML or XML content to Java objects. JAXB is a separate project, but it becomes part of JDK in Java 6.
JAXB tutorial
Using JAXB is very simple. it uses annotations. we need to use annotations on Java objects to indicate the creation of XML, and then we need to create allaller to convert the object to XML, use Unmarshaller to convert XML into Java objects. In this tutorial, we will learn most of the JAXB annotations and learn to convert objects to XML using Marshaller and convert XML to objects using Unmarshaller.

JiBX

JiBX is a very powerful framework used to convert XML and Java objects to each other. it is widely used for multi-application integration using XML as the data transmission format, for example, Web Service and message-based system integration.
JiBX tutorial
Many frameworks can be used for XML conversion, such as JAXB and XMLBeans. However, JiBX uses different methods for XML Binding and conversion, jiBX generates Ant scripts to execute these tasks during compilation Through the tool class. This method removes the traditional two-step processing method, greatly reducing the processing time.

XPath

XPath provides syntax definitions for some XML documents, and XPath expressions use query strings to select some XML documents. Using an XPath expression, we can find any node.
XPath tutorial
The javax. xml. xpath package provides support for XPath. XPathExpression can be created using the factory method provided by the XPath API. this tutorial describes how to use the XPath expression to find XML nodes.

XML-related tasks

Generate general XML from XSD in Eclipse
If you are engaged in Web Service related work, you need to use XSD and test WebService, you need to generate XML files from the XSD file. Eclipse provides a very simple way to help you complete.
Verify XML validity using XSD
Java XML Validation API can use XSD to verify XML files. This tutorial will use the javax. xml. validation. Validator class.
Java XML attribute file
Generally, configuration parameters of our java application are stored in the property file. The property file of Java can be either a properties file of a key-value pair or an XML file. This example describes how to use XML as an attribute file and obtain relevant information from the attribute file.
SOAP XML
Soap is an XML-based transmission Protocol. Soap is short for Simple Object Access Protocol. Soap is a lightweight data exchange mechanism based on XML and cross-platform.
Format an XML document
Use a practical tool class to print XML and convert the XML Document object to a string.
Conversion between String and Document
Sometimes, in Java programming, we get a string whose content is in XML data format. to process it, we need to convert it into a Document object. Or, for debugging purposes, you need to convert the Document Object to string output. There are two practical methods to convert String and Document objects. This article will introduce you.

Original article address :#

XML is a widely used technology for data transmission and storage. Java provides a variety of APIs to parse XML, such as DOM, SAX, StAX, and JAXB. There are also some other APIs for parsing XML, such as JDOM. The purpose of this tutorial is to explore using different types of APIs to parse XML and learn to use XML to execute some common tasks.

Dom xml parsing

DOM parsing is the simplest method of parsing. XML files are loaded into the memory, and XML can be parsed by traversing Node nodes. DOM parsing is suitable for small files with less content. when the file is large, the parsing speed is very slow and takes up a lot of memory.
Read xml files
This article describes how to use DOM to parse XML files and convert XML content to Java objects.
Generate XML file
This article describes how to convert a Java object to an XML file and store it on a local disk.
Modify an XML file
The DOM parsing mechanism can also be used to modify XML data. This article describes how to use the DOM parsing mechanism to add, delete, modify, and attribute elements.

Sax xml parsing

The Java SAX parsing mechanism provides APIs for parsing XML documents. unlike DOM, the SAX parsing mechanism does not load all XML files into the memory, but reads XML documents in sequence. It is event-based parsing. we need to implement a Custom Handler class and use its callback method to parse XML files. When parsing large files, it is more efficient than the DOM parsing mechanism.
Read XML files
Learn how to create our callback Handler class and read XML content to a List.

StAX XML parsing

The full name of Java StAX is Java Streaming API for XML, which provides specific XML parsing implementation. StAX consists of two sets of APIs: cursor-based APIs and iterator-based APIs.
Use the StAX Iterator API to read XML files
In this tutorial, we will learn how to use StAX iteration to read XML.
Use the StAX Iterator API to generate an XML file
In this tutorial, we will learn how to use the StAX API based on the iterator to generate XML.
Use the StAX Cursor API to read XML files
This article describes how to use the StAX Cursor API to read XML data to Java objects.
Use the StAX Cursor API to generate an XML file
The Java StAX Cursor API is very direct in creating XML and outputting data in it. Create an XMLStreamWriter object and write data to the object.

Jdom xml parsing

JDOM provides excellent APIs to make it easier to read, modify, and generate XML files. It provides a packaging class for you to select the specific implementation from the SAX parsing, DOM parsing, StAX event parsing.
The advantage of using JDOM is that you can switch the parser from SAX and dom stax, and provide a Factory method for client applications to choose implementation.
JDOM reads XML files
In this tutorial, we will learn how to use JDOM to read XML files.
JDOM generates XML files
In this tutorial, we will learn how to use JDOM to write XML files. JDOM Document provides a convenient way to create elements and attributes. The XMLOutputter class can be used to write a Document object to any OutputStream or Writer object.

JAXB

The full name of JAXB is Java Architecture for XML Binding. Using the APIs provided by JAXB, you can easily convert Java objects to XML or XML content to Java objects. JAXB is a separate project, but it becomes part of JDK in Java 6.
JAXB tutorial
Using JAXB is very simple. it uses annotations. we need to use annotations on Java objects to indicate the creation of XML, and then we need to create allaller to convert the object to XML, use Unmarshaller to convert XML into Java objects. In this tutorial, we will learn most of the JAXB annotations and learn to convert objects to XML using Marshaller and convert XML to objects using Unmarshaller.

JiBX

JiBX is a very powerful framework used to convert XML and Java objects to each other. it is widely used for multi-application integration using XML as the data transmission format, for example, Web Service and message-based system integration.
JiBX tutorial
Many frameworks can be used for XML conversion, such as JAXB and XMLBeans. However, JiBX uses different methods for XML Binding and conversion, jiBX generates Ant scripts to execute these tasks during compilation Through the tool class. This method removes the traditional two-step processing method, greatly reducing the processing time.

XPath

XPath provides syntax definitions for some XML documents, and XPath expressions use query strings to select some XML documents. Using an XPath expression, we can find any node.
XPath tutorial
The javax. xml. xpath package provides support for XPath. XPathExpression can be created using the factory method provided by the XPath API. this tutorial describes how to use the XPath expression to find XML nodes.

XML-related tasks

Generate general XML from XSD in Eclipse
If you are engaged in Web Service related work, you need to use XSD and test WebService, you need to generate XML files from the XSD file. Eclipse provides a very simple way to help you complete.
Verify XML validity using XSD
Java XML Validation API can use XSD to verify XML files. This tutorial will use the javax. xml. validation. Validator class.
Java XML attribute file
Generally, configuration parameters of our java application are stored in the property file. The property file of Java can be either a properties file of a key-value pair or an XML file. This example describes how to use XML as an attribute file and obtain relevant information from the attribute file.
SOAP XML
Soap is an XML-based transmission Protocol. Soap is short for Simple Object Access Protocol. Soap is a lightweight data exchange mechanism based on XML and cross-platform.
Format an XML document
Use a practical tool class to print XML and convert the XML Document object to a string.
Conversion between String and Document
Sometimes, in Java programming, we get a string whose content is in XML data format. to process it, we need to convert it into a Document object. Or, for debugging purposes, you need to convert the Document Object to string output. There are two practical methods to convert String and Document objects. This article will introduce you.

The above is the description of the Java & Xml tutorial (1). For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.