Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中将非文本内容设置为DOM元素_Android_String_Dom_Document - Fatal编程技术网

在Android中将非文本内容设置为DOM元素

在Android中将非文本内容设置为DOM元素,android,string,dom,document,Android,String,Dom,Document,我从资产中读取了一个html模板,并希望将html添加到某个分区中。 我将模板解析为org.w3c.dom.Document,并将div作为org.w3c.dom.Element获取,如下所示: Element wrapper = doc.getElementById("wrapper"); wrapper.setTextContent(article.getHtmlString()); 我尝试像这样添加我的html文本: Element wrapper = doc.getElementBy

我从资产中读取了一个html模板,并希望将html添加到某个分区中。

我将模板解析为org.w3c.dom.Document,并将div作为org.w3c.dom.Element获取,如下所示:

Element wrapper = doc.getElementById("wrapper");
wrapper.setTextContent(article.getHtmlString());
我尝试像这样添加我的html文本:

Element wrapper = doc.getElementById("wrapper");
wrapper.setTextContent(article.getHtmlString());
不幸的是,所有的“”都被转换,之后看起来像这样:

<
我希望能以一种不会破坏标记的方式附加html字符串


有人吗?

在将文档转换为字符串后,我使用正则表达式并使用字符串替换方法填充html内容

docHtmlString.replace("<div id='wrapper'>, "<div id='wrapper'>" + article.getHtmlString());
docHtmlString.replace(“,”+article.getHtmlString());
实际使用dom并不是一个真正的解决方案,但在尝试添加一些html字符串内容时,它是一个可行的替代方案