DocIO 在将 HTML 转换为 SFDT 时抛出错误。

huangapple go评论77阅读模式
英文:

DocIO throw an error when convert from html to sfdt

问题

我切换了从我的旧的Primeface RichEditor到syncfusion WordEditor,并且我使用下面的类将html转换为sdft。

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import com.syncfusion.docio.FormatType;
import com.syncfusion.docio.WordDocument;
import com.syncfusion.ej2.wordprocessor.WordProcessorHelper;

public class SFDTAdapter {
	
	public static String sfdtToRtf(String sfdt) throws Exception {
		return WordProcessorHelper.save(sfdt, com.syncfusion.ej2.wordprocessor.FormatType.Rtf).toString();
	}
	
	public static String rtfToSfdt(String rtf) throws Exception {
		byte[] bytes = rtf.getBytes(StandardCharsets.UTF_8);
		InputStream stream = new ByteArrayInputStream(bytes);
		WordDocument document = new WordDocument(stream, FormatType.Rtf);
		String sfdt =  WordProcessorHelper.load(document);
		document.close();
		stream.close();
		return sfdt;
	}
	
	
	public static String htmlToSfdt(String html) throws Exception {
		byte[] bytes = html.getBytes(StandardCharsets.UTF_8);
		InputStream stream = new ByteArrayInputStream(bytes);
		WordDocument document = new WordDocument(stream, FormatType.Html);
		String sfdt = WordProcessorHelper.load(document);
		document.close();
		stream.close();
		return sfdt;
	}
	
	public static String sfdtToHtml(String sfdt) throws Exception {
		return WordProcessorHelper.save(sfdt, com.syncfusion.ej2.wordprocessor.FormatType.Html).toString();
	}
}

然而,当我处理旧的记录时,我遇到了以下问题:“元素类型 'br' 必须由匹配的结束标记 '
' 终止”。根据我所读的,这是因为 DocIO 验证内容是否符合 xhtml 1 格式。是否有办法告诉 DocIO 忽略错误,或者不验证该格式?

英文:

I switched from my old Primeface RichEditor to syncfusion WordEditor, and I use the bellow class to transform from html to sdft

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import com.syncfusion.docio.FormatType;
import com.syncfusion.docio.WordDocument;
import com.syncfusion.ej2.wordprocessor.WordProcessorHelper;

public class SFDTAdapter {
	
	public static String sfdtToRtf(String sfdt) throws Exception {
		return WordProcessorHelper.save(sfdt, com.syncfusion.ej2.wordprocessor.FormatType.Rtf).toString();
	}
	
	public static String rtfToSfdt(String rtf) throws Exception {
		byte[] bytes = rtf.getBytes(StandardCharsets.UTF_8);
		InputStream stream = new ByteArrayInputStream(bytes);
		WordDocument document = new WordDocument(stream, FormatType.Rtf);
		String sfdt =  WordProcessorHelper.load(document);
		document.close();
		stream.close();
		return sfdt;
	}
	
	
	public static String htmlToSfdt(String html) throws Exception {
		byte[] bytes = html.getBytes(StandardCharsets.UTF_8);
		InputStream stream = new ByteArrayInputStream(bytes);
		WordDocument document = new WordDocument(stream, FormatType.Html);
		String sfdt = WordProcessorHelper.load(document);
		document.close();
		stream.close();
		return sfdt;
	}
	
	public static String sfdtToHtml(String sfdt) throws Exception {
		return WordProcessorHelper.save(sfdt, com.syncfusion.ej2.wordprocessor.FormatType.Html).toString();
	}
}

However, when I process old registers I get the following issue "The element type 'br' must be terminated by the matching end-tag </br>". According to what I readed, this is because DocIO validates that the content follow the format xhtml 1. Is there a way to say to DocIO that ignore errors, or doesn't verify that format?

答案1

得分: 0

关于 - 我遇到了以下问题:“元素类型 'br' 必须由匹配的结束标签终止:”

输入的HTML字符串格式不正确('br'元素没有结束标签)。

Essential Word library(DocIO)仅支持格式正确的HTML(给定的HTML内容必须符合XHTML 1.0格式的规则或标准)。要解决此问题,请在HTML字符串中使用格式正确的HTML,例如'br'元素具有正确的起始和结束标签。

关于 - 是否有一种方法告诉DocIO忽略错误,或不验证该格式?

没有。在DocIO库中无法忽略这些错误并验证格式。要解决此问题,请在DocIO中使用格式正确的HTML,即HTML字符串具有正确的元素起始和结束标签。

英文:

Regarding - I get the following issue "The element type 'br' must be terminated by the matching end-tag:

The input HTML string is not well formatted HTML (‘br’ element doesn’t have an end tag).

Essential Word library (DocIO) supports only well formatted HTML (the given HTML content must be in accordance with rules or standards of XHTML 1.0 format). To resolve this issue, please use well-formatted HTML like ‘br’ element has proper start and end tags in the HTML string.

Regarding - Is there a way to say to DocIO that ignore errors, or doesn't verify that format?

No. There is no way to ignore that errors and verify that format in DocIO library. To resolve the issue, please use well-formatted HTML in DocIO like HTML string that has proper element’s start and end tags.

huangapple
  • 本文由 发表于 2023年6月29日 01:00:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定