java - 将 XML 转换为 Markdown 格式文本
问题描述
我正在尝试将 XML 转换为 Markdown
public static Document transformXmlToMarkdown(String xml) throws TransformerException {
Source source = new StreamSource(new StringReader(xml));
TransformerFactory tFactory=TransformerFactory.newInstance();
DOMResult result = new DOMResult();
Transformer transform = tFactory.newTransformer(new StreamSource(new StringReader(markdown)));
transform.transform(source, result);
return (Document) result.getNode();
}
markdown
中的new StringReader(markdown)
基于这里。这段代码的问题是我没有转换。
输入:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<en-note>
<div>
<br/>
</div>
<div>
<br/>
</div>
<en-media hash="" type="application/octet-stream"/>
<div>
<br/>
</div>
<div>This is my first Evernote blog with image/photo attached.</div>
<div>
<br/>
</div>
<div>This is another line. </div>
<div>
<br/>
</div>
<div>Some
<i>formatting </i>also for
<b>some </b>lines.
</div>
</en-note>
输出应该是:
This is my first Evernote blog with image/photo attached.
This is another line.
Some _formatting_ also for **some** lines.
任何提示将不胜感激。
解决方案
您提到的 xslt 脚本可用于将某种 HTML 转换为 Markdown。
您的 XML 不是 HTML。您的 XML 以根元素“en-note”开头,并且在 XSLT 中没有匹配,因此不处理该元素。
推荐阅读
- php - 通过php将图像发送到aws
- django - Django在modelfield的字符串值中搜索
- flutter - 文本数据更改时颤动动画过渡
- hadoop - 创建需要动态配对的 Hive 表时是否有任何列顺序?
- encoding - 将 SAS 编码更改为 utf-8
- jquery - 将选定的复选框附加到另一个 div
- c# - Inkscape 扩展:我无法打开临时的 ink_ext_XXXXXX.svg 文件,因为 Inkscape 本身正在使用它
- visual-studio - 一次部署多个 aws netcore lambda 函数
- java - 解析数据并删除不可见字符,如回车
- android - Gradle 项目同步失败,原因:org/gradle/api/internal/FeaturePreviews