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 766507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:03:31+00:00 2026-05-14T17:03:31+00:00

I’m working on a webservices client app and I have it mostly working. I

  • 0

I’m working on a webservices client app and I have it mostly working. I can retrieve and read data from the third-party webservice fine. Now I need to submit some data and I’m stuck.

The classes for the objects I’m retrieving/submitting were generated from XSD files via the xjc tool. The part I’m stuck on is turning one of those objects into an XML tree to submit to the webservice.

When I retrieve/send a request from/to the ws, it contains a ‘payload’ object. This is defined in java code as (partial listing):

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PayloadType", propOrder = {
    "compressed",
    "document",
    "any",
    "format"
})
public class PayloadType {

    @XmlElement(name = "Compressed")
    protected String compressed;
    @XmlElement(name = "Document")
    protected List<String> document;
    @XmlAnyElement
    protected List<Element> any;
    protected String format;

    public List<Element> getAny() {
        if (any == null) {
            any = new ArrayList<Element>();
        }
        return this.any;
    }

}

The only field I’m concerned with is the ‘any’ field which contains an XML tree. When I retrieve data from the ws, I read that field with something like this:
(‘root’ is of org.w3c.dom.Element type and is the result of calling ‘getAny().get(0)’ on the payload object)

NodeList nl = root.getElementsByTagName("ns1:Process"); // "ns1:Process" is an XML node to do something with
if (nl != null && nl.getLength() > 0) {
    for (int i = 0; i < nl.getLength(); i++) {
        Element proc = (Element) nl.item(i);
        try {
            // do something with the 'proc' Element here...
        } catch (Exception ex) {
            // handle problems here...
        }
    }
}

Submitting data is where I’m stuck. How do I take a java object created from one of the classes generated from XSD and turn it into an Element object that I can add to the ‘any’ List of the payload object?? For instance, if I have a DailyData class and I create and populate it with data:

DailyData dData = new DailyData();
dData.setID = 34;
dData.setValues = "3,5,76,23";

How do I add that ‘dData’ object to the ‘any’ List of the payload object? It has to be an Element. Do I do something with a JAXBContext marshaller? I’ve used that to dump the ‘dData’ object to the screen to check the XML structure.

I’m sure the answer is staring me in the face but I just can’t see it!

Dave

UPDATE: Got it working with the below code snippet:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document doc = dbf.newDocumentBuilder().newDocument();

JAXBContext context = JAXBContext.newInstance(DailyData.class);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(dData, doc);


PayloadType payload = new PayloadType();
payload.getAny().add((Element)doc.getFirstChild());
  • 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-14T17:03:32+00:00Added an answer on May 14, 2026 at 5:03 pm

    The List<Element> field type is usually generated by XJC when you have something like this in the schema:

    <xs:any processContents="skip" maxOccurs="unbounded" minOccurs="0" />
    

    The key here is processContents="skip", which means “anything goes” – any well-formed XML can go in here. Because it’s a free-for-all, all XJC can do is represent it as a DOM, and it becomes your responsibility to handle that payload.

    If you remove processContents="skip", then JAXB will make an attempt to bind the payload to an object model, if it can match the payload XML to a class in the JAXBContext. In this case, XJC will generate this a field of type List<Object>.

    This may not seem like a improvement, but this List can contain Element (if the JAXBContext doesn’t recognise the payload as something it can bind to), or JAXBElement (if it does recognise it). The latter contains the bound version of the payload, and is much easier to handle.

    This is all described further here.

    If you cannot modify the schema, and are stuck with processContents="skip", then you’re going to have to jump through hoops. You can build another JAXBContext that knows about your payload classes, and use that to marshal to an Element (using something like marshaller.marshal(payload, new DOMResult()). You can then dump that element into the payload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.