将Soap标签添加到生成的XML中

时间:2015-04-24 18:53:54

标签: java xml soap xsd spring-jms

我需要将此XML更改为下面的XML。我目前使用XSD生成现有的xml,java util类使用Jibx设置值和编组,并使用JMS发送消息。任何帮助,将不胜感激。什么是解决这个问题最简单的方法。

请求XSD:

<xsd:schema 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:complexType name="Request">
            <xsd:annotation>
                <xsd:documentation>
                    A request.
                </xsd:documentation>
            </xsd:annotation>
            <xsd:sequence>
                <xsd:element name="Header" type="Header" />
                <xsd:element name="RequestBody" type="RequestBody" />
            </xsd:sequence>
        </xsd:complexType>

标题的XSD:

<xsd:complexType name="Header" abstract="true">
        <xsd:annotation>
            <xsd:documentation>
                The definition of a Header.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="HeaderVersion" type="HeaderVersion" />
            <xsd:element name="ServiceName" type="ServiceName" />
            <xsd:element name="ServiceVersion" type="ServiceVersion" />
            <xsd:element name="ServiceType" type="ServiceType" />
            <xsd:element name="ApplicationId" type="ApplicationId" />           
        </xsd:sequence>
    </xsd:complexType>

现有生成的XML:

<Request><Header><HeaderVersion>1.0</HeaderVersion><ServiceName>Service</ServiceName><ServiceVersion>1.0</ServiceVersion><ServiceType>search</ServiceType><ApplicationId>1</ApplicationId></Header><RequestBody><UserInfo><UserId>SYSTEM</UserId><RoleNames/></UserInfo><GetRequest><Type>123</Type></GetRequest></RequestBody></Request>

这应该生成:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <Header>
            <ServiceVersion>1.0</ServiceVersion>
            <ServiceName>Service</ServiceName>
            <HeaderVersion>1.0</HeaderVersion>
        </Header>
        <TimeStamp>
            <Millis>1429884619658</Millis>
            <Formatted>2015 04 24 14:10:19</Formatted>
        </TimeStamp>
    </soapenv:Header>
    <soapenv:Body>
        <ns9:GetRequest xmlns="" xmlns:ns6="http://example.com/schemas/common" xmlns:ns7="http://example.com/schemas/service" xmlns:ns8="http://example.com/schemas/common" xmlns:ns9="http://example.com/schemas/service">
            <Type>123</Type>
        </ns9:GetRequest>
    </soapenv:Body>
</soapenv:Envelope>

0 个答案:

没有答案