论坛首页 入门技术论坛

ProcessingInstruction中xml-stylesheet位置的放置

浏览 1506 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-01-11  

  由于生成的xml中需要有:

 

  <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 一个指令 

 

  Element root = new Element("configuration");
  Document doc = new Document(root);
  ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet",
    "type=\"text/xsl\" href=\"configuration.xsl\"");
  doc.addContent(pi);

 

  运行了好多遍。一直位于xml的最下面,百思不得其解啊。!

 

  How   do   I   add   a   PI   or   Comment   before   the   root   element?  
   
  You   must   access   the   document   content   as   a   List.   Either   get   the   list   and   add   content   to   its   head,   or   set   the   list   of   content   explicitly.  
   
  doc.getContent().add(0,   pi);     //正解
  or  
  doc.setContent(listOfContent);

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics