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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:25:34+00:00 2026-06-11T13:25:34+00:00

Below is the xml I have to work with: <watermarks identifier=X hostname=X> <watermark type=XX

  • 0

Below is the xml I have to work with:

<watermarks identifier="X" hostname="X">
   <watermark type="XX" value="1234"/>
   <watermark type="YY" value="1234" />
</watermarks>

I just want to get a list of Watermark objects using JAXB without creating a new Watermarks class. Is it possible or should I have to create a Watermarks class which contains a list of Watermark objects ?

Thanks.

  • 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-06-11T13:25:35+00:00Added an answer on June 11, 2026 at 1:25 pm

    You could use a StAX (JSR-173) XMLStreamReader to parse the XML document (an implementation is included in the JDK/JRE since Java SE 6). Then you could advance it to advance to each watermark element and then have JAXB (JSR-222) unmarshal that.

    Demo

    Assuming the Watermark class is annotated with @XmlRootElement you could do the following.

    import javax.xml.bind.*;
    import javax.xml.stream.*;
    import javax.xml.transform.stream.StreamSource;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Watermark.class);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
    
            StreamSource source = new StreamSource("input.xml");
            XMLInputFactory xif = XMLInputFactory.newFactory();
            XMLStreamReader xsr = xif.createXMLStreamReader(source);
            xsr.nextTag(); // Advance to "watermarks" element
            xsr.nextTag(); // Advance to "watermark" element
    
            while(xsr.getLocalName().equals("watermark")) {
                 Watermark object = (Watermark) unmarshaller.unmarshal(xsr);
                 System.out.println(object);
                 xsr.nextTag();
            }
        }
    
    }
    

    Full Example

    • JAXB unmarshalling of "generic" real world documents

    Generic List Wrapper Class

    In my answer to the question below I provided an example of a generic list wrapper class that you may find useful.

    • How to marshalling the muliptle object using jaxb
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have xml file like Below and Device class and i want get List<Device>
I have this below code and it work fine header (content-type: text/xml); $xml =
I have an xml as below < Image>ImageValue1 <Type>png</Type> <Value>ImageValue1</ Value> </ Image> Here
I have a simple file XML like below: <brandName type=http://example.com/codes/bmw# abbrev=BMW value=BMW />BMW</brandName> <maxspeed>
I have an XML document containing contact information as seen below: <contact type=individual> <firstname>Some</firstname>
I have xml file below: <?xml version=1.0 encoding=utf-8 ?> <?xml-stylesheet version=1.0 type=text/xml href=template.xsl ?>
I have a table td like below. if i use this.xml the below value
I have an xml string below that I've turned into an object using $content
I have an xml file likes below. <?xml version=1.0 encoding=utf-8 ?> <Book> <Title>Title</Title> <Content>Content</Content>
I have a xml that looks like below <xsl:template match=//xml> <xsl:for-each select=//z:row> <ul class

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.