如何将 XHTML 插入 XML

发布于 2024-07-24 07:39:22 字数 481 浏览 8 评论 0原文

我现在正在使用 JDOM。 我想不出一个本质上应该是一个简单问题的解决方案。

我有一个有效的 XHTML 字符串:

M&A €

如何将其插入到 XML DOM 中,如下所示?


  M&A
  €

(此 XML 然后转到 XSL 转换器,然后为浏览器呈现 XHTML)

我提出了以下“伪”解决方案,但我不确定如果可能的话:

取消转义不是 XML 实体的实体,然后插入。
仅重新转义 XML 实体,然后 HTML 取消转义整个字符串,然后插入。

塔拉斯

I'm working with JDOM at the moment. I can't think of a solution which what should essentially be an easy problem.

I have a valid XHTML string:

<b>M&A</b> €

How do I insert this into the XML DOM as follows?

<parentNode>
  <b>M&A</b>
  €
</parentNode>

(this XML then goes off to an XSL transformer, which then renders XHTML for the browser)

I've come up with the following 'pseudo' solutions, but I'm not sure if they're possible:

Unescape entities which aren't XML entities, then insert.
Reinscape only XML entites, then HTML unescape the entire string, then insert.

Taras

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤寂小茶 2024-07-31 07:39:22

我想您可以使用 JTidy 将命名实体转换为编号实体。 之后,XHTML 也是有效的 XML。

I guess you can use JTidy to transform named entities to numbered ones. After that, the XHTML is also valid XML.

绾颜 2024-07-31 07:39:22

而欧元; 是有效的 XHTML 实体,但不是有效的 XML 实体。

不幸的是,我对 JDOM 一无所知,但如果可能的话,您可以尝试添加 DTD 实体声明,例如 。 并且,也许将所有 XHTML 标记放入其正确的命名空间中 (...< ;/x:b>)

While € is valid XHTML entity it is not valid XML one.

Unfortunately, I don't know anything about JDOM, but if it is possible you may try adding DTD entity declarations like <!ENTITY euro "€">. And, maybe, put all XHTML tags into their proper namespace (<parentNode xmlns:x="http://www.w3.org/1999/xhtml"><x:b>...</x:b></parentNode>)

乱世争霸 2024-07-31 07:39:22

您的 XHTML 内容的字符串

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

创建一个包含

,在本例中 M&A

+

</html>

然后解析这个字符串得到一个文档。 然后获取根元素内的所有内容(这将是您的 XHTML 内容)并将其放置在您的parentNode 元素内。 您可能需要考虑到内容来自不同的文档。

Create a string containing

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

+

your XHTML content, in this case <b>M&A</b> €

+

</html>

and then parse this string to obtain a document. Then get all the content inside the root element, that will be your XHTML content and place it inside your parentNode element. You may need to take into account that the content comes from a different document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文