java xml解析器_Java XML解析器

java xml解析器

Java XML parser is used to work with xml data. XML is widely used technology to transport or store data. That’s why there are many java xml parsers available.

Java XML解析器用于处理xml数据。 XML是广泛用于传输或存储数据的技术。 这就是为什么有许多可用的Java xml解析器的原因。

Java XML解析器 (Java XML Parser)

java xml parser

Some of the commonly used java xml parsers are;


一些常用的java xml解析器是:

  1. DOM Parser

    DOM解析器
  2. SAX Parser

    SAX解析器
  3. StAX Parser

    StAX解析器
  4. JAXB

    杰克斯

There are some other APIs also available for XML parsing in java, for example JDOM and JiBX.

还有一些其他API可用于Java中的XML解析,例如JDOMJiBX

This java xml parser tutorial is aimed to explore different kinds of XML processing API’s and to learn some common tasks we need to perform with XML such as read, write and edit.

该java xml解析器教程旨在探索各种XML处理API,并学习我们需要使用XML执行的一些常见任务,例如读取,写入和编辑。

Java XML分析器– DOM (Java XML Parser – DOM)

DOM Parser is the easiest java xml parser to learn. DOM parser loads the XML file into memory and we can traverse it node by node to parse the XML. DOM Parser is good for small files but when file size increases it performs slow and consumes more memory.

DOM解析器是最容易学习的Java xml解析器。 DOM解析器将XML文件加载到内存中,我们可以逐节点遍历该文件以解析XML。 DOM解析器非常适合小型文件,但是当文件大小增加时,它的执行速度会变慢,并占用更多内存。

  1. Read XML File
    This article shows how to use DOM Parser to parse XML file to Object.

    读取XML文件
    本文介绍如何使用DOM解析器将XML文件解析为对象。
  2. Write XML File
    This article explains how to use DOM Parser to write Object data to XML file.

    写入XML档案
    本文介绍了如何使用DOM分析器将对象数据写入XML文件。
  3. Edit XML File
    DOM Parser can be used to edit XML data also. This article shows how to add elements, remove elements, edit element values, edit attributes in an XML document using DOM Parser.

    编辑XML档案
    DOM分析器还可用于编辑XML数据。 本文介绍了如何使用DOM分析器在XML文档中添加元素,删除元素,编辑元素值以及编辑属性。

Java XML分析器– SAX (Java XML Parser – SAX)

Java SAX Parser provides API to parse XML documents. SAX Parsers are different than DOM parser because it doesn’t load complete XML into memory and read xml document sequentially. It’s an event based parser and we need to implement our Handler class with callback methods to parse XML file. It’s more efficient than DOM Parser for large XML files in terms of time and memory usage.

Java SAX Parser提供了用于解析XML文档的API。 SAX解析器与DOM解析器不同,因为它不会将完整的XML加载到内存中并不会顺序读取xml文档。 这是一个基于事件的解析器,我们需要使用回调方法实现Handler类以解析XML文件。 就时间和内存使用而言,对于大型XML文件,此方法比DOM分析器更有效。

  1. Read XML File
    Learn how to create our Callback Handler class to read XML file to list of Objects using SAX Parser.

    读取XML文件
    了解如何创建我们的回调处理程序类,以使用SAX Parser将XML文件读取到对象列表。

StAX Java XML解析器 (StAX Java XML Parser)

Java Streaming API for XML (Java StAX) provides implementation for processing XML in java. StAX consists of two sets of API – cursor based API and iterator based API. I have covered this java xml parser extensively in different posts.

用于XML的Java Streaming API( Java StAX )提供了用于在Java中处理XML的实现。 StAX由两组API组成- 基于游标的API基于迭代器的API 。 我已经在不同的文章中广泛介绍了此java xml解析器。

  1. Read XML File Using StAX Iterator API
    In this tutorial we will learn how to read XML iteratively using Java StAX (XMLEventReader).

    使用StAX Iterator API读取XML文件
    在本教程中,我们将学习如何使用Java StAX( XMLEventReader )迭代读取XML。
  2. Write XML File Using StAX Iterator API
    In this tutorial we will see how we can write XML file in java using StAX Iterator based API (XMLEventWriter).

    使用StAX Iterator API写入XML文件
    在本教程中,我们将看到如何使用基于StAX Iterator的API( XMLEventWriter )在Java中编写XML文件。
  3. Read XML File Using StAX Cursor API
    This article shows how to use StAX Cursor API (XMLStreamReader) to read XML data to Object.

    使用StAX Cursor API读取XML文件
    本文介绍如何使用StAX Cursor API( XMLStreamReader )将XML数据读取到Object。
  4. Write XML File Using StAX Cursor API
    Java StAX Cursor API is very straight forward in creating XML and outputting it. We need to create XMLStreamWriter object and write data into it. This tutorial explains it in detail with example.

    使用StAX Cursor API编写XML文件
    Java StAX Cursor API在创建XML和输出XML方面非常直接。 我们需要创建XMLStreamWriter对象并将数据写入其中。 本教程将通过示例对其进行详细说明。

Java XML解析器– JDOM (Java XML Parser – JDOM)

JDOM provides a great Java XML parser API to read, edit and write XML documents easily. JDOM provides wrapper classes to chose your underlying implementation from SAX Parser, DOM Parser, STAX Event Parser and STAX Stream Parser.
Benefit of using JDOM is that you can switch from SAX to DOM to STAX Parser easily, you can provide factory methods to let client application chose the implementation.

JDOM提供了一个出色的Java XML解析器API,可以轻松读取,编辑和写入XML文档。 JDOM提供包装器类,以从SAX分析器,DOM分析器,STAX事件分析器和STAX流分析器中选择基础实现。
使用JDOM的好处是,您可以轻松地从SAX切换到DOM,再切换到STAX Parser,可以提供工厂方法来让客户端应用程序选择实现。

  1. JDOM Read XML File
    In this tutorial, we will learn how to read XML file to Object using JDOM XML Parser.

    JDOM读取XML文件
    在本教程中,我们将学习如何使用JDOM XML Parser将XML文件读取到Object。
  2. JDOM Write XML File
    In this tutorial we will learn how to write XML file in Java using JDOM. JDOM Document provides methods to easily create elements and attributes. XMLOutputter class can be used to write the Document to any OutputStream or Writer object.

    JDOM写入XML文件
    在本教程中,我们将学习如何使用JDOM用Java编写XML文件。 JDOM Document提供了轻松创建元素和属性的方法。 XMLOutputter类可用于将Document写入任何OutputStreamWriter对象。
  3. JDOM Edit XML File
    JDOM provides very neat way to manipulate XML files, using JDOM is very easy and the code looks clean and readable. In this tutorial we will learn how to add element, remove element, edit element value and edit attribute value.

    JDOM编辑XML文件
    JDOM提供了一种非常整洁的方式来处理XML文件,使用JDOM非常容易,并且代码看起来清晰易读。 在本教程中,我们将学习如何添加元素,删除元素,编辑元素值和编辑属性值。

Java XML解析器– JAXB (Java XML Parser – JAXB)

Java Architecture for XML Binding (JAXB) provides API for converting Object to XML and XML to Object easily. JAXB was developed as a separate project but it was used widely and finally became part of JDK in Java 6.

XML绑定Java体系结构(JAXB)提供了API,可轻松地将Object转换为XML并将XML转换为Object。 JAXB是作为一个单独的项目开发的,但得到了广泛的使用,最终成为Java 6中JDK的一部分。

  1. JAXB Tutorial
    Using JAXB is very easy and it uses annotations. We need to annotate Java Object to provide instructions for XML creation and then we have to create Marshaller to convert Object to XML. Unmarshaller is used to convert XML to java Object. In this tutorial we will learn most widely used JAXB annotations and how to convert a Java Object to XML (Marshalling) and XML to Java Object (Unmarhsalling).

    JAXB教程
    使用JAXB非常容易,并且使用批注。 我们需要注释Java Object以提供XML创建的说明,然后我们必须创建Marshaller将Object转换为XML。 Unmarshaller用于将XML转换为Java Object。 在本教程中,我们将学习使用最广泛的JAXB批注,以及如何将Java对象转换为XML( 编组 )以及如何将XML对象转换为Java对象( Unmarhsalling )。

Java XML解析器– JiBX (Java XML Parser – JiBX)

JiBX is a very powerful framework for converting XML data to java object and vice versa. It is very useful in applications integration where XML is the format for data transfer, for example, Web Services and Legacy Systems Integration based on Message Oriented Model (MOM).

JiBX是一个非常强大的框架,用于将XML数据转换为Java对象,反之亦然。 它在XML是数据传输格式的应用程序集成中非常有用,例如,基于消息定向模型(MOM)的Web服务和旧系统集成。

  1. JiBX Tutorial
    There are many frameworks available for XML transformation such as JAXB and XMLBeans but JiBX differs in the approach for XML binding and transformation process. JiBX performs these tasks via utility classes generated at compile time via ant scripts. This approach reduces the processing time by moving away from the traditional two-step process with other parsers to a single step.

    JiBX教程
    有许多可用于XML转换的框架,例如JAXB和XMLBeans,但是JiBX在XML绑定和转换过程的方法上有所不同。 JiBX通过在编译时通过ant脚本生成的实用程序类来执行这些任务。 这种方法通过将与其他解析器一起使用的传统两步处理转移到一个步骤,从而减少了处理时间。

XPath (XPath)

XPath provides syntax to define part of an XML document. XPath Expression is a query language to select part of the XML document based on the query String. Using XPath Expressions, we can find nodes in any xml document satisfying the query string.

XPath提供了定义XML文档一部分的语法。 XPath Expression是一种查询语言,用于根据查询字符串选择XML文档的一部分。 使用XPath表达式,我们可以在任何xml文档中找到满足查询字符串的节点。

  • XPath Tutorial
    javax.xml.xpath package provides XPath support in Java. To create XPathExpression, XPath API provide factory methods. In this tutorial we will use XPath query language to find out elements satisfying given criteria.

    XPath教程
    javax.xml.xpath包在Java中提供了XPath支持。 为了创建XPathExpression,XPath API提供了工厂方法。 在本教程中,我们将使用XPath查询语言找出满足给定条件的元素。

杂项Java XML解析器任务 (Miscellaneous Java XML parser tasks)

  1. Generate Sample XML from XSD in Eclipse
    If you work on web services, you must have been using XSD’s and to test the webservice, you need to generate XML from XSD file. Eclipse provide a very easy way to generate XML from XSD.

    在Eclipse中从XSD生成示例XML
    如果您使用Web服务 ,则必须一直在使用XSD,并且要测试Web服务,需要从XSD文件生成XML。 Eclipse提供了一种非常容易的方法来从XSD生成XML。
  2. Validate XML against XSD
    Java XML Validation API can be used to validate XML against an XSD. javax.xml.validation.Validator class is used in this tutorial to validate xml file against xsd file.

    针对XSD验证XML
    Java XML验证API可用于针对XSD验证XML。 本教程中使用javax.xml.validation.Validator类针对xsd文件验证xml文件。
  3. Java XML Property File
    Usually we store configurations parameters for java applications in a property file. In java property file can be a normal property file with key-value pairs or it can be an XML file also.
    In this example, we will learn how to write property XML file and then read properties from XML property files.

    Java XML属性文件
    通常,我们将Java应用程序的配置参数存储在属性文件中。 在java中,属性文件可以是具有键值对的普通属性文件,也可以是XML文件。
    在此示例中,我们将学习如何编写XML属性文件,然后从XML属性文件读取属性。
  4. SOAP XML
    Soap is an Xml based transport protocol. Soap stands for Simple Object Access Protocol. Soap is a lightweight mechanism for exchanging structured and typed information. As it is XML based so it is language and platform independent.
    In this tutorial you will learn about SOAP XML and how can we create it using Liquid XML Studio software.

    SOAP XML
    肥皂是一种基于Xml的传输协议。 肥皂代表简单对象访问协议。 Soap是用于交换结构化和类型化信息的轻量级机制。 由于它基于XML,所以它与语言和平台无关。
    在本教程中,您将学习SOAP XML以及如何使用Liquid XML Studio软件创建它。
  5. Format XML Document
    A utility class with methods for pretty printing XML and converting XML Document to String and String to XML document.

    格式化XML文档
    一个实用程序类,其中包含用于漂亮地打印XML并将XML Document转换为String以及将String转换为XML文档的方法。
  6. Convert Document to String and String to Document
    Sometimes while programming in java, we get String which is actually an XML and to process it, we need to convert it to XML Document (org.w3c.dom.Document). Also for debugging purpose or to send to some other function, we might need to convert Document object to String. Two utility methods to convert String to XML Document and XML Document to String.

    将文档转换为字符串并将字符串转换为文档
    有时在用Java编程时,我们得到的String实际上是XML,并且要对其进行处理,我们需要将其转换为XML Document(org.w3c.dom.Document)。 同样出于调试目的或发送给其他功能,我们可能需要将Document对象转换为String。 将String转换为XML Document和将XML Document转换为String的两种实用方法。

I will be adding more java XML parser tutorials here as and when I post more, so don’t forget to bookmark it for future use.

当我发表更多文章时,我将在这里添加更多的Java XML解析器教程,因此请不要忘记将其添加书签以供将来使用。

翻译自: https://www.journaldev.com/1240/java-xml-parser

java xml解析器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值