下面,将以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
public class HTMLtoXML { //加载html文件 //保留为XML格式import com.spire.doc.*;文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html
public static void main {
//创立Document类的对象
Document doc = new Document;文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html
doc.loadFromFile;文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html
doc.saveToFile;
}
}
转换效果:文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html
—文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html 文章源自微观生活(93wg.com)微观生活-https://93wg.com/4655.html
评论