把bbs作为xmlns定义,如xmlns:bbs="http://xxx.yyy.com/..."

解决方案 »

  1.   


    楼上说的是:
    Element bbs_lastDate = item.addElement("bbs_lastDate");
    bbs_lastDate.addNamespace("bbs","lastDate");
    这样子吗?
    但是结果不是我想要的,
     <bbs_lastDate xmlns:bbs="lastDate">【帖子最后一条回复的发布时间】</bbs_lastDate>
      

  2.   

    org.dom4j.IllegalAddException: No such namespace prefix: ha is in scope on: org.dom4j.tree.DefaultElement@1968e23 [Element: <book attributes: [org.dom4j.tree.DefaultAttribute@14da8f4 [Attribute: name show value "yes"]]/>] so cannot add element: ha:ha
    at org.dom4j.tree.AbstractElement.addElement(AbstractElement.java:841)
    at com.jtt.tpm.common.ManagerXML_dom4j.addChildNode(ManagerXML_dom4j.java:151)
    at com.jtt.tpm.common.ManagerXML_dom4j.main(ManagerXML_dom4j.java:94)
      

  3.   


    就是您楼下所说的一样  报错的提示org.dom4j.IllegalAddException: No such namespace prefix: ha is in scope on: org.dom4j.tree.DefaultElement@1968e23 [Element: <book attributes: [org.dom4j.tree.DefaultAttribute@14da8f4 [Attribute: name show value "yes"]]/>] so cannot add element: ha:ha 
    at org.dom4j.tree.AbstractElement.addElement(AbstractElement.java:841) 
    at com.jtt.tpm.common.ManagerXML_dom4j.addChildNode(ManagerXML_dom4j.java:151) 
    at com.jtt.tpm.common.ManagerXML_dom4j.main(ManagerXML_dom4j.java:94) 
      

  4.   

    你不明白我的意思。":"在xml标签中有特殊意义,一般用于指定xmlnamespace,你不能用他来作为标签名的一部份。建议去复习一下xml语法。
      

  5.   

    你应该在document节点加namespace.
    Document doc = DocumentHelper.createDocument(); 
    Element document = doc.addElement("document"); 
    document.addNamespace("bbs","http://yourdnsname/"); 
    Element bbs_lastDate = document.addElement("bbs:lastDate"); 
    bbs_lastDate.setText("aaaa"); 
      

  6.   

    19楼正解,在添加bbs时应该用addNamespace方法,而不是addAttribute,虽然两者很像。