【问题标题】:How to convert lt and gt type values into XML format如何将 lt 和 gt 类型值转换为 XML 格式
【发布时间】:2019-10-29 07:25:36
【问题描述】:

我从 SOAP 响应中得到这样的输出。我需要将"<CLIOutput>" 这样的输出转换为<CLIOutput>

请建议如何将其转换为 XML。这是否可以在 XPath、XSLT 或 XML 的帮助下完成。

<output>
            <line index="1">&lt;CLIOutput&gt;</line>
            <line index="2">  &lt;Results&gt;</line>
            <line index="3">    &lt;ReturnCode&gt;0&lt;/ReturnCode&gt;</line>
            <line index="4">    &lt;EventCode&gt;23000&lt;/EventCode&gt;</line>
            <line index="5">    &lt;EventSummary&gt;CLI command completed successfully.&lt;/EventSummary&gt;</line>
            <line index="6">  &lt;/Results&gt;</line>
            <line index="7">  &lt;Data&gt;</line>
            <line index="8">    &lt;Row&gt;</line>
            <line index="9">      &lt;Tag&gt;cp.20191028151231&lt;/Tag&gt;</line>
            <line index="10">      &lt;Time&gt;2019-10-28 11:12:31 EDT&lt;/Time&gt;</line>
            <line index="11">      &lt;Validated&gt;Validated&lt;/Validated&gt;</line>
            <line index="12">      &lt;Deletable&gt;No&lt;/Deletable&gt;</line>
            <line index="13">    &lt;/Row&gt;</line>
            <line index="14">    &lt;Row&gt;</line>
</output>

【问题讨论】:

  • 您的问题不清楚,请发布您收到的完整参考资料以及您想要什么,假设如果我们交谈 < >在 那么你的 XML 格式就不正确了。

标签: xml xslt xpath automation cdata


【解决方案1】:

您可以使用disable-output-escaping="yes" 转换如下代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="1.0">

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="line">
      <xsl:value-of select="." disable-output-escaping="yes"/>
  </xsl:template>

</xsl:stylesheet>

查看链接: https://xsltfiddle.liberty-development.net/bFWR5E6

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-30
    • 2020-08-30
    • 2017-03-21
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    相关资源
    最近更新 更多