2015-09-04 95 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应用服务器提供给浏览器时。