2015-09-04 99 views
0

我想HTML存儲與空標籤XML格式自行關閉標籤:MarkLogic生成XML

<body xmlns="http://www.w3.org/1999/xhtml"> 
     <div class="WordSection1" xmlns=""> 
      <p class="ChapterNumber">Chapter 6</p> 
      <h1 class="ChapterTitle">The Legislature and the <br/>Electoral System</h1> 
      <p class="ChapterSub-Title"> </p> 
      <div style=""></div> 
     </div> 
    </body> 

在MarkLogic存儲後,我得到空自閉標籤

<body xmlns="http://www.w3.org/1999/xhtml"> 
     <div class="WordSection1" xmlns=""> 
      <p class="ChapterNumber">Chapter 6</p> 
      <h1 class="ChapterTitle">The Legislature and the <br />Electoral System</h1> 
      <p class="ChapterSub-Title"> </p> 
      <div style="" /> 
     </div> 
    </body> 

它生成無效的XHTML。我怎樣才能得到原始的XML,無論是自我關閉的元素和空元素,因爲它是原始文件?

+0

它們在語義上是相同的,那麼爲什麼這是一個問題呢? – Sobrique

+0

感謝您的即時回覆,你的意思是「語義相同」? –

+0

就XML規範而言意味着相同的東西。 – Sobrique

回答

1

正如其他人所指出的,這是一個序列化問題。 xdmp:output選項是你的朋友在這裏。 (也請看XQuery and XSLT serialization spec。)HTML序列化是一種特殊情況。

declare option xdmp:output "method=html"; 
xdmp:set-response-content-type("text/html"), 
'<!DOCTYPE html>', 
<html lang="en"> 
<head> 
<meta charset="utf-8" /> 
<title>Untitled</title> 
<script type="text/javascript"> 
if(1 &lt; 2 &amp;&amp; 3 &lt; 4) {{ 
    alert("&amp;"); 
}} 
</script> 
</head> 
<body> 
    <h2>Empty textarea</h2> 
    <textarea></textarea> 
    <h2>Empty div</h2> 
    <div></div> 
</body> 
</html> 

結果

<!DOCTYPE html> 
<html lang="en"><head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta 
charset="utf-8"><title>Untitled</title><script type="text/javascript"> 
if(1 < 2 && 3 < 4) { 
alert("&"); 
} 
</script></head><body><h2>Empty textarea</h2><textarea></textarea><h2>Empty 
div</h2><div></div></body></html> 

沒有輸出選項你

<!DOCTYPE html> 
<html lang="en"><head><meta charset="utf-8"/><title>Untitled</title><script 
type="text/javascript"> 
if(1 &lt; 2 &amp;&amp; 3 &lt; 4) { 
alert("&amp;"); 
} 
</script></head><body><h2>Empty textarea</h2><textarea/><h2>Empty 
div</h2><div/></body></html> 

注意,這個例子還演示瞭如何序列化DOCTYPE(這不是XML數據的一部分模型)以及如何設置HTTP內容類型,例如,將HTML直接從MarkLogic應用服務器提供給瀏覽器時。