Accessing XMLBeans by DOM

XMLBeans can be used to bind XML data from web services requests to Java beans. A JAR library containing this Java beans can be generated compiling XSD files with XMLBeans scomp utility. Once this Java beans are available on the system, XML attributes can be accessed using simple getters and setters from Java.

Besides, Spring WS provides a functionality in order to marshall XML incoming requests to XMLBeans extending AbstractMarshallingPayloadEndpoint class. Inside this method, XPath or DOM can be used to avoid reflection or casting.

public class EndPoint extends org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint {

    protected Object invokeInternal(Object requestObject) throws Exception {

        XmlObject xo = (XmlObject)requestObject;

        if (xo.getDomNode().getFirstChild().getFirstChild().getChildNodes().item(2).getFirstChild().getNodeValue().equals("A")) {

            [...]

        }

    }

}

Imagine you have the same header defined on your XSD files for all incoming requests to your system. By making this you are able to read a fixed field from your XMLBeans without casting or reflecting.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s