java对象转换成OMElement

 

public OMElement getBody(Object obj, String nameSpace) {

		XMLStreamReader reader = BeanUtil.getPullParser(obj);

		StreamWrapper parser = new StreamWrapper(reader);

		StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.createStAXOMBuilder(
				OMAbstractFactory.getOMFactory(), parser);

		OMElement element = staxOMBuilder.getDocumentElement();

		OMNamespace ns = OMAbstractFactory.getOMFactory().createOMNamespace(
				nameSpace, "m");

		element.setNamespace(ns);

		return element;
	}

你可能感兴趣的:(java)