【问题标题】:How to deserialize xml in which a node contains html tags?如何反序列化节点包含html标签的xml?
【发布时间】:2012-07-07 09:36:19
【问题描述】:
<Translation> (  benzene  OR  pyrobenzole  OR  pyrobenzol  OR  &quot;phenyl      hydride&quot;              OR  phene  OR  &quot;fenzen  czech  &quot;  cyclohexatriene  &quot;coal  naphtha&quot;  OR  &quot;benzolo  italian  &quot;  benzole  benzol  &quot;benzen  polish  &quot;  &quot;benzeen  dutch  &quot;  ) The chemical name <b>benzene</b> was identified.<br>The following terms were added from ChemIDplus:<br><b>pyrobenzole</b><br><b>pyrobenzol</b><br><b>phenyl hydride</b><br><b>phene</b><br><b>fenzen  czech </b><br><b>cyclohexatriene</b><br><b>coal naphtha</b><br><b>benzolo  italian </b><br><b>benzole</b><br><b>benzol</b><br><b>benzen  polish </b><br><b>benzeen  dutch </b><br>CAS Registry Number: <b>71-43-2</b><br></Translation>

我从 Web 服务获取字符串,但它没有在 cdata 部分发送 html。 我得到的错误是: System.Xml.XmlException:第 1 行的“br”开始标记与结束标记不匹配

我正在使用 .net 3.5,webclient 来使用 REST web 服务。

【问题讨论】:

  • 您应该发布实际的 xml,因为您的示例有一个结束 br 标记。
  • 在 XML 文档中嵌入未编码的 HTML 听起来是个糟糕的主意。
  • 修改 Web 服务以在 cdata 部分中对 html 进行编码。
  • 已编辑以添加实际的 XML。我无法将 Web 服务更改为外部服务。有什么方法可以解析 XML 并提取 HTML?

标签: c# html xml .net-3.5 xml-serialization


【解决方案1】:

我知道这个问题。我可以通过包含 HTML 的命名空间来解决它。

xmlns="http://www.w3.org/1999/xhtml"

&lt;br /&gt;&lt;hr /&gt;&lt;input /&gt; 等所有空元素都会引发此错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    相关资源
    最近更新 更多