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 怎么去掉阿?
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 怎么去掉阿?
你试下这个
不知道可以不可以
使用removeNamespaceDeclaration(Namespace additionalNamespace)这个方法。你看看它的Element对象api就知道了
rootElement.setNamespace(ns1); 这不是你自己加进去的吗????