Axis2中的工具和字符串彼此转化
在Web Service中界说了巨大范例之后,Axis2会生成对应的类工具。这些类都是可以序列化的。
可以把这些类的实例和字符串之间做彼此转化。
// 工具转换成字符串
StringWriter stringWriter = new StringWriter();
XMLStreamWriter xmlStreamWriter = StAXUtils
.createXMLStreamWriter(stringWriter);
MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new MTOMAwareXMLSerializer(
xmlStreamWriter);
userCredentialsType.serialize(new QName(
"http://newautovideo.com/siteengine/ws/types", "ns1"),
OMAbstractFactory.getSOAP11Factory(), mtomAwareXMLStreamWriter);
xmlStreamWriter.flush();
xmlStreamWriter.close();
String omElementString = stringWriter.toString();
System.out.println("OM String ==> " + omElementString);
// 字符串转换成工具
XMLStreamReader xmlReader = StAXUtils
.createXMLStreamReader(new ByteArrayInputStream(omElementString
.getBytes()));
UserCredentialsType result = UserCredentialsType.Factory
.parse(xmlReader);
System.out.println("OM Object==> " + result.getUserID());