2012-05-30 26 views
3

假設我有一個帶有描述字段的對象。該字段可以具有帶有一些html標記的字符串值。防止JAXB轉義我的元素內的HTML標記

"Say <b xmlns="http://www.w3.org/1999/xhtml">Hello</b> Wold" 

當這個對象被封,我檢索結果如下一個XML

<description>Say &lt;b&gt;Hello&lt;/b&gt; World</description> 

相反,我想HTML標記留轉義

<description>Say <b xmlns="http://www.w3.org/1999/xhtml">Hello</b> World</description> 

是否有辦法爲了實現這一點,例如在我的領域的註釋?

感謝您的幫助

+1

以下應該有所幫助:http://blog.bdoughan.com/2011/04 /xmlanyelement-and-non-dom-properties.html –

+1

[使用JAXB提取XML元素的內部文本]的可能重複(http://stackoverflow.com/questions/5537416/using-jaxb-to-extract-inner-文本的XML的元素) –

回答

0

這是正確的方式如何預防的Marshaller到HTML特殊字符轉義:

marshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler() { 
      @Override 
      public void escape(char[] ch, int start, int length, boolean isAttVal, 
           Writer out) throws IOException { 
       out.write(ch, start, length); 
      } 
     });