Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1049789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:40:18+00:00 2026-05-16T16:40:18+00:00

I have 2 sets of XSD’s, one that generates RPC based calls, and another

  • 0

I have 2 sets of XSD’s, one that generates RPC based calls, and another that defines the product specific methods. The RpcType object (generated by JAXB2) has a ‘setRpcOperation’ method defined by:

RpcType.setRpcOperation(JAXBElement<? extends RpcOperationType>)

That ‘RpcOperation’ object should be the ‘specific product method’ described above. One example is (also generated by JAXB2):

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "get-user-stats", propOrder = {
    "reset"
})
public class GetUserStats {

    protected Boolean reset;

    /**
     * Gets the value of the reset property.
     * 
     * @return
     *     possible object is
     *     {@link Boolean }
     *     
     */
    public Boolean isReset() {
        return reset;
    }

    /**
     * Sets the value of the reset property.
     * 
     * @param value
     *     allowed object is
     *     {@link Boolean }
     *     
     */
    public void setReset(Boolean value) {
        this.reset = value;
    }

}

Now, is it possible to create an instance of ‘GetUserStatus’ and add it to the RpcType object via setRpcOperation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:40:18+00:00Added an answer on May 16, 2026 at 4:40 pm

    This type of scenario is common:

    • One schema to represent the message
    • Multiple schemas to represent the payload.

    Below is one way this could be done:

    Message Schema – message.xsd

    Have one XML schema to represent your message envelope. Introduce one type to represent the body of the message. This type will be extended by the different payloads.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       targetNamespace="http://www.example.org/message" 
       xmlns="http://www.example.org/message" 
       elementFormDefault="qualified">
    
        <xsd:element name="message">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="body" type="body"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    
        <xsd:complexType name="body">
        </xsd:complexType>
    
    </xsd:schema>
    

    Payload Schema – customer.xsd

    This schema corresponds to a specific type of message payload. Notice how the customer type extends the body type from the message schema.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema 
        targetNamespace="http://www.example.org/customer" 
        xmlns="http://www.example.org/customer"
        xmlns:m="http://www.example.org/message" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="qualified"> 
    
        <xsd:import schemaLocation="message.xsd" namespace="http://www.example.org/message"/>
    
        <xsd:complexType name="customer">
            <xsd:complexContent>
                <xsd:extension base="m:body">
                    <xsd:sequence>
                        <xsd:element name="name" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:extension>
            </xsd:complexContent>
        </xsd:complexType>
    
    </xsd:schema>
    

    org.example.message.package-info

    This class was generated from message.xsd.

    @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/message", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
    package org.example.message;
    

    org.example.message.Message

    This class was generated from message.xsd.

    package org.example.message;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "body"
    })
    @XmlRootElement(name = "message")
    public class Message {
    
        @XmlElement(required = true)
        protected Body body;
    
        public Body getBody() {
            return body;
        }
    
        public void setBody(Body value) {
            this.body = value;
        }
    
    }
    

    org.example.message.Body

    This class was generated from message.xsd.

    package org.example.message;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "body")
    public class Body {
    
    }
    

    org.example.customer.package-info

    This class was generated from customer.xsd.

    @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.org/customer", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
    package org.example.customer;
    

    org.example.customer.Customer

    This class was generated from customer.xsd.

    package org.example.customer;
    
    import javax.xml.bind.annotation.*;
    import org.example.message.Body;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "customer", propOrder = {
        "name"
    })
    
    public class Customer extends Body {
    
        @XmlElement(required = true)
        protected String name;
    
        public String getName() {
            return name;
        }
    
        public void setName(String value) {
            this.name = value;
        }
    
    }
    

    Demo Class

    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    
    import org.example.customer.*;
    import org.example.message.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Message.class, Customer.class);
    
            Message message = new Message();
            Customer customer = new Customer();
            customer.setName("Jane Doe");
            message.setBody(customer);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(message, System.out);
        }
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <message xmlns="http://www.example.org/message" xmlns:ns2="http://www.example.org/customer">
        <body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:customer">
            <ns2:name>Jane Doe</ns2:name>
        </body>
    </message>
    

    EDIT #1

    In response to your second question (Cast JAXB2 generated object to JAXBElement?)

    I don’t see where the JAXBElement comes into play with this example. I am able to run the following code:

    import generated.GetFailedLoginCount;
    import ietf.params.xml.ns.netconf.base._1.RpcType;
    
    public class Demo {
    
        public static void main(String[] args) {
            RpcType rpc = new RpcType(); 
            rpc.setMessageId("123"); 
            GetFailedLoginCount rpcOperation = new GetFailedLoginCount(); 
            rpc.setRpcOperation(rpcOperation);
        }
    }
    

    EDIT #2

    After changing the import to import to http://www.iana.org/assignments/xml-registry/schema/netconf.xsd I’m seeing the same behaviour as you.

    To set the property correctly you will need to do something like:

    RpcType rpc = new RpcType(); 
    GetFailedLoginCount rpcOperation = new GetFailedLoginCount(); 
    rpcOperation.setReset(true);
    JAXBElement<GetFailedLoginCount> rpcOperationJE = new JAXBElement(new QName("foo"), GetFailedLoginCount.class, rpcOperation);
    rpc.setRpcOperation(rpcOperationJE);
    

    JAXBElement supplies the element name for the GetFailedLoginCount value. This is required because the element corresponding to the rpcOperation property is substitutable:

    <xs:element name="get-config" type="getConfigType" substitutionGroup="rpcOperation" /> 
    

    In your schema that imports netconf.xsd you should have an element of type “get-failed-login-count” that can be substituted for “rpcOperation”. This will be supplied as a QName to the JAXBElement. Since we used element name “foo” above the schema update would look like:

    <xs:element name="foo" type="get-failed-login-count" substitutionGroup="rpcOperation" /> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XSD schema that defines multiple elements in a document. Two sets
Suppose you have sets of Fluent conventions that apply to specific groups of mappings,
I'm working with Jquery in Drupal. I have sets of four blocks that all
I have multiple sets of xy pairs that I want to plot. I want
Lets say that I have sets that I know are already sorted such as
Have two sets of data (two tables) for patient records, one 1999-2003, the other
I have two sets of data that contains some of the same information. This
I have sets of similar divs that I am toggleing with some basic code
What shortcut sets have you seen that you would consider logical and easy to
I have two sets of arrays. I need to get the letters that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.