Java 将HTML转为XML

小微 科技Java 将HTML转为XML已关闭评论103字数 723阅读模式
摘要本文介绍如何通过Java后端程序代码来展示如何将html转为XML。此功能通过采用Word API- Free Spire.Doc for Java 提供的Document.sav...

下面,将以html转为xml格式为例,介绍怎么实现转换。下列是详细办法及步骤。


通过 Maven仓库 下载导入,如下配置pom.xml:文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

<repositories>
<repository>
<id>com.e-iceblue</id>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>

如需手动导入,需要下载 jar包 到本地,然后解压,找到lib文件夹下的Spire.Doc.jar文件。在IDEA中打开“Project Structure”界面,执行如图步骤将本地路径下的jar文件手动引入Java程序:文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

转换时,可参考如下代码步骤:文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

  • 创立Document类的对象。
  • 调用Document.loadFromFile办法加载HTML文件。
  • 通过Document.saveToFile办法保留为XML格式到指定路径。

Java文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

import com.spire.doc.*;文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

public class HTMLtoXML {
public static void main {
//创立Document类的对象
Document doc = new Document;文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

//加载html文件
doc.loadFromFile;文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

//保留为XML格式
doc.saveToFile;
}
}

转换效果:文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html 文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html

 
小微
  • 版权声明: 本文部分文字与图片资源来自于网络,转载此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请立即通知我们(管理员邮箱:81118366@qq.com),情况属实,我们会第一时间予以删除,并同时向您表示歉意,谢谢!
  • 转载请务必保留本文链接:https://93wg.com/4655.html