求救:soap消息中的方法及参数的前缀是如何加上的?

bufegar 2008-05-04 09:30:33
soap消息代码片段如下:

<soap:Body>
<DocumentLiteral xmlns="http://www.contoso.com">
<address>
<Street>One Microsoft Way</Street>
<City>Redmond</City>
<Zip>98052</Zip>
</address>
</DocumentLiteral>
</soap:Body>
</soap:Envelope>

我想将<address>显示为<ws:address>的方法,如何处理,其他的参数也是按此类型显示
望各位高手不吝赐教,先行谢过.
...全文
383 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
添加一个命名空间就有了。。



/**
* 创建xml
*
* @param method
* 要访问的方法(webservice专用)
* @param path
* xml路径
* @param elements
* 子元素
*/
static public Document createXML(Element method, String path,
Element... elements)
{
// declare root element
Element root = new Element("Envelope");
// declare header element
Element header = new Element("Header");
// declare body element
Element body = new Element("Body");
// declare three namespaces
// first param is prefixs,second param is uri
Namespace soap = Namespace.getNamespace("soap",
"http://schemas.xmlsoap.org/soap/envelope/");
Namespace xsd = Namespace.getNamespace("xsd",
"http://www.w3.org/2001/XMLSchema");
Namespace xsi = Namespace.getNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
// put namespace to root element
root.addNamespaceDeclaration(soap);
root.addNamespaceDeclaration(xsd);
root.addNamespaceDeclaration(xsi);
// put header element to root element
root.addContent(header);
// put body element to root element
root.addContent(body);
// with root set namespace prefixs
root.setNamespace(soap);
// with header set namespace prefix
header.setNamespace(soap);

// with body element set namespace prefixs
body.setNamespace(soap);
body.addContent(method);

for (int i = 0; i < elements.length; ++i)
{
method.addContent(elements[i]);
}
// declare document element
Document doc = new Document(root);
// declare xml format class
Format format = Format.getPrettyFormat();
// set encoding for xml
format.setEncoding("UTF-8");
// set indent for xml
format.setIndent(" ");
// set expaned empty elements for xml
format.setExpandEmptyElements(true);
// xml file output class
XMLOutputter outputter = new XMLOutputter(format);
// output
try
{
outputter.output(doc, new FileWriter(path));
} catch (IOException e)
{
e.printStackTrace();
System.out.println("File path is not correct!" + e.getMessage());
}
return doc;
}

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧