DocumentHelper用法

DocumentHelper用法

DocumentHelper用法

最新推荐文章于 2022-10-03 10:14:46 发布

风的王子

最新推荐文章于 2022-10-03 10:14:46 发布

阅读量2w

收藏

13

点赞数

12

分类专栏:

java 类技术总结

文章标签:

java基础

java 类技术总结

专栏收录该内容

40 篇文章

订阅专栏

本文详细介绍了如何使用DocumentHelper类的parseText方法解析XML文本,并通过Element接口的getName和getText方法获取XML元素的名称和文本内容。此外,文章还阐述了Document类及其继承关系,以及Element接口的主要方法,提供了XML文档操作的基础知识。

注意:Node是element的父类。

public static void main(String args[]){

String s="" +

"" +

"" +

"440305198012255411" +

"sdfsdf" +

"19801225" +

"m" +

"";

try {

Document doc = DocumentHelper.parseText(s);

Node root=doc.getRootElement();

System.out.println(root.getName());

} catch (Exception e) {

e.printStackTrace();

}

}

一、DocumentHelper类的主要静态方法:

1.parseText

public static Document parseText(String text)

throws DocumentException

parseText parses the given text as an XML document and returns the newly created Document.

Parameters:

text - the XML text to be parsed

Returns:

a newly parsed Document

Throws:

DocumentException - if the document could not be parsed

二、Document接口的主要方法:

1.getRootElement

public Element getRootElement()

Returns the root Element for this document.

Returns:

the root element for this document

三、Element接口的主要方法:

1.getText(这个是element接口的方法)

返回当前元素的文本内容,如果元素没有文本内容,则返回空。

public String getText()

Returns the text value of this element without recursing through child elements. This method iterates through all Text,CDATA and Entitynodes that this element contains and

appends the text values together.

Specified by:

getText in interface Node

Returns:

the textual content of this Element. Child elements are not navigated. This method does not return null;

2.getName(这个是node接口的方法,由于element继承node,所有,element也可以调用该方法)

public String getName()

getName returns the name of this node. This is the XML local name of the element, attribute, entity or processing instruction. For CDATA and Text nodes this method will

return null.

Returns:

the XML name of this node

四、Document类的继承结构

public interface Document

extends Branch

public interface Branch

extends Node

Document接口继承Branch,Branch接口又继承Node接口,而Node接口有个方法,经常用到如下:

List selectNodes(String xpathExpression)

selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.

Parameters:

xpathExpression - is the XPath expression to be evaluated

Returns:

the list of Node or String instances depending on the XPath expression

确定要放弃本次机会?

福利倒计时

:

:

立减 ¥

普通VIP年卡可用

立即使用

风的王子

关注

关注

12

点赞

13

收藏

觉得还不错?

一键收藏

知道了

1

评论

分享

复制链接

分享到 QQ

分享到新浪微博

扫一扫

举报

举报

专栏目录

DocumentHelper解析xml文件

北辰

12-10

7679

DocumentHelper解析xml文件

1 条评论

您还未登录,请先

登录

后发表或查看评论

DocumentHelper和SAXReader解析XML字符串

lmb55的专栏

03-08

1万+

最近在看湖北中烟OA门户的项目,中烟门户里面解析XML文档使用的是DocumentHelper,之前做的智能导航项目里面解析XML使用的是SAXReader,很好奇它们有什么区别,于是就查资料将两者的用法简单总结了一下。SAXReader用法示例package com.eway.signature.action;import java.io.FileInputStream;

import java.

Java DocumentHelper与SAXReader对xml文档的解析

lkckly的博客

01-09

1011

XML文件解析

XML的解析方式分为四种:

1、DOM解析;

2、SAX解析;

3、JDOM解析;

4、DOM4J解析。

其中前两种属于基础方法,是官方提供的平台无关的解析方式;后两种属于扩展方法,它们是在基础的方法上扩展出来的,只适用于java平台。

今天我们就来着重讲一讲用的最多的一种,也就是第四种DOM4J解析。在此之前我们需要导入两个jar包来帮助我们完成代码。

分别是dom4j-1.6.1.jar和jaxen-1.1-beta-6.jar;

解析xml文档有两种方式

第一种:DocumentHel

DocumentHelper

08-24

836

注意:Node是element的父类。public static void main(String args[]){String s="" +

"" +

"" +

"440305198012255411"

documentHelper

longcxm1的博客

11-01

346

注意:Node是element的父类。

public static void main(String args[]){

String s="" +

"" +

"" +

"440305198012255411" +

"sdfsdf" +

"19801225" +

"m" +

&quo

demo4j使用方法及DocumentHelper解析XML转JSON示例

在这个描述中,使用了`DocumentHelper.parseText(xmljson)`来表示将一个包含XML和JSON混合的字符串解析为XML格式的Document对象。 2. **获取XML的根元素** 解析后的Document对象允许我们通过`getRootElement()`...

documenthelper.parsetext用法

03-16

documenthelper.parsetext是一个函数,用于将文本解析为可编辑的文档对象。它可以将纯文本转换为格式化文本,例如添加段落、字体、颜色等样式。该函数通常用于文本编辑器或文档处理软件中,以便用户可以对文本进行...

DocumentHelper.parseText 的使用

03-29

使用 DocumentHelper.parseText 方法,需要先导入 org.dom4j.DocumentHelper 类,然后调用该类的静态方法 parseText,传入一个 XML 字符串作为参数,即可得到一个 Document 对象。 示例代码: ```java import org....

DocumentHelper 解析XML文件

Cc_Rain

10-09

1192

系统对接 外部交换平台 使用XML形式 拼接比较费时繁琐。

DocumentHelper 工具类。

Document doc = null;

String xxx = SendNC.readToString("test.xml");

String xml = xxx.substring(xxx.indexOf("

Stri...

DocumentHelper创建xml文件

ernesto的博客

11-01

1105

public static Map generate(HttpServletRequest request, LicenseCompanyBase licenseCompanyBase, ILicenseCompanyBaseDao licenseCompanyBaseDao, IDataDictionaryDao dataDictionaryDao) {

Map

Excel Helper Document

ResetOTER

08-07

490

What’s Excel Helper

It can help you export Excel to xml orprotobuf, and you don’t need to write a lot of script to read them.

解析XML文件(字符串)的两种方法-----SAXReader 与 DocumentHelper

热门推荐

yumingxian2020的专栏

06-12

4万+


一、用SAXReader 方式解析:实例测试类TestXML

package *

import java.io.ByteArrayInputStream;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

pub

java saxreader 字符串_DocumentHelper 和SAXReader 解析xml 字符串

weixin_32218919的博客

02-16

352

DocumentHelper 解析xml字符串String xml=com.jetsen.platform.util.FileUtil.getFileContent(request.getSession().getServletContext().getRealPath("/WEB-INF/platform-app-interface.xml"));org.dom4j.Document doc =...

DocumentHelper 和SAXReader 解析xml 字符串

weixin_30312563的博客

11-27

204

DocumentHelper 解析xml字符串

String xml=com.jetsen.platform.util.FileUtil.getFileContent(request.getSession().getServletContext().getRealPath("/WEB-INF/platform-app-interface.xml")); org.dom4j.Docume...

POI Illegal reflective access by org.apache.poi.util.DocumentHelper (XX) to method XXX问题解决

旭东怪的博客

10-03

1367

1、在JDK11的环境下,针对org.apache.poi.xssf.usermodel.XSSFCellStyle进行反射赋值操作,导致报错。解决办法:将项目的JDK版本改为8即可。

saxReader和documentHelper对xml的解析与创建

Code The Future

01-19

3131

前段时间做了一个两个项目之间同步数据的接口,主要就是用到了xml作为数据的载体,主要技术就是解析和创建xml.

解析和创建xml的方法有很多,以前一直用dom4j的saxReader比较多.这次做项目接触到了一个documentHelper.所以记录一下dom4j中saxReader和documentHelper对于xml相关的使用.源码看这里

maven依赖

dom4j

04-19

1072

创建xml文档的两种方法

1、DocumentHelper类的createDocument()方法

DocumentHelper document=DocumentHelper.createDocument();

2、DoucumentFactory也可以创建xml文档

DocumentFactory documentfactory=DocumentFactory.getInstence(

相关推荐

除了「复仇者联盟」漫威超级英雄团队还有哪些?
轩辕传奇手游公众号怎么领Q币 轩辕传奇手游微信公众号Q币领取方法
都9012年了!用户数量一年不如一年,QQ到底还能活多久?
德标/法标和欧标插头插座的区别
betvip5365

德标/法标和欧标插头插座的区别

📅 10-01 👁️ 1345
请病假条范文怎么写?
365投注规则

请病假条范文怎么写?

📅 10-15 👁️ 3920
如何测试服务器tcp协议
betvip5365

如何测试服务器tcp协议

📅 10-09 👁️ 7780
关于“攻城掠地七擒孟获需要多少影子”的最新资讯内容
春雨计步器好不好
365投注规则

春雨计步器好不好

📅 10-03 👁️ 1398
苹果4s换个wifi模块多少钱
365投注规则

苹果4s换个wifi模块多少钱

📅 06-28 👁️ 1360