【问题标题】:How to write @xml:space="preserve" with Stax如何使用 Stax 编写 @xml:space="preserve"
【发布时间】:2012-12-03 09:55:13
【问题描述】:

我用 stax 写一个 XML 文件。

我的问题是如何将属性xml:space="preserve" 添加到我的元素中?

  • 我需要声明xml 前缀吗? AFAIK,通常没有必要。
    • 如果我不声明,stax 会抱怨首选前缀不能是 null(javax.xml.stream.XMLStreamException: Prefix cannot be null)
    • 如果我在XMLStreamWriter上声明前缀为setPrefix("xml", "http://www.w3.org/1998/xml"),似乎没有任何效果。在调试模式下,我看到 XMLStreamWriter 的 nsmap 没有“xml”的条目
  • 当我使用writeAttribe("http://www.w3.org/1998/xml", "space", "preserve") 编写属性时引发异常。有没有具体的方法呢?

【问题讨论】:

    标签: xml xml-serialization stax


    【解决方案1】:

    我找到了解决方法:

    writeAttribute("xml:space", "preserve")
    

    但这是无意义的,因为xml:space 不是本地名称,是吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2016-03-10
      相关资源
      最近更新 更多