Element rootElement = new Element("definitions");
Document myDocument = new Document(rootElement);
rootElement.setAttribute("name",component.getName()); 
String targetName;
// name space
targetName="http://"+component.getSystemName()+".com/"+component.getName()+".wsdl";
rootElement.setAttribute("targetName", targetName);
Namespace ns1 = Namespace.getNamespace("http://schemas.xmlsoap.org/wsdl");
rootElement.setNamespace(ns1);
// rootElement.addNamespaceDeclaration(ns1);
Namespace ns2 = Namespace.getNamespace("tns", targetName);
rootElement.addNamespaceDeclaration(ns2);
... Element typeElement=new Element("type");
rootElement.addContent((Element)typeElement);
....但是我生成的文件
<definitions xmlns="http://schemas.xmlsoap.org/wsdl" xmlns:tns="http://simple-demo.com/Compress.wsdl" xmlns:xsd="http://simple-demo.com/Compress.xsd" ...>
  <type xmlns="">...
这个type 里的xmlns 怎么去掉阿?

解决方案 »

  1.   

    removeAttribute("xmlns");
    你试下这个 
    不知道可以不可以
      

  2.   

    去掉命名空间的声明
    使用removeNamespaceDeclaration(Namespace additionalNamespace)这个方法。你看看它的Element对象api就知道了
      

  3.   

    Namespace ns1 = Namespace.getNamespace("http://schemas.xmlsoap.org/wsdl"); 
    rootElement.setNamespace(ns1); 这不是你自己加进去的吗????
      

  4.   

    我试了一下,可以在你的新建节点里加入setNamespace(ns1);就可以去掉了
      

  5.   

    哈,哈,关于xmlns=""的问题,5楼的正解。可以用这个方法去掉,不必要的xmlns的定义。