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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:44:22+00:00 2026-05-15T16:44:22+00:00

Theres some pretty nasty XML that i’d like to unmarshall to a java object

  • 0

Theres some pretty nasty XML that i’d like to unmarshall to a java object using JaxB. Most of it has seemed quite straightforward so far – but I am kinda stuck on this:

            <assets>
                <asset type="fixed">74,414</asset>
                <asset type="current">1,022,069</asset>
                <asset type="other">0</asset>
                <total type="assets">1,096,483</total>
            </assets>

This is the relevant part of the dtd

<!ELEMENT assets (asset|total)*>
<!ELEMENT asset (#PCDATA)>
<!ATTLIST asset
type CDATA #REQUIRED>
<!ELEMENT total (#PCDATA)>
<!ATTLIST total
type CDATA #REQUIRED>

Any ideas? Or should I give up trying to use JAXB for this?

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-05-15T16:44:23+00:00Added an answer on May 15, 2026 at 4:44 pm

    Looking at the XML and the DTD, I created the XSD of the structure:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      elementFormDefault="qualified">
      <xs:element name="assets">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" ref="asset"/>
            <xs:element maxOccurs="unbounded" ref="total"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="asset">
        <xs:complexType mixed="true">
          <xs:attribute name="type" use="required" type="xs:string"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="total">
        <xs:complexType mixed="true">
          <xs:attribute name="type" use="required" type="xs:string"/>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    

    Use xjc to generate the Java classes annotated with the JAXB binding annotations from the XSD. Then use the unmarshaller to unmarshal it to Java object.

    Edit

    Generated Java classes:

    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlValue;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "asset",
        "total"
    })
    @XmlRootElement(name = "assets")
    public class Assets {
    
        @XmlElement(required = true)
        protected List<Asset> asset;
        @XmlElement(required = true)
        protected List<Total> total;
    
        public List<Asset> getAsset() {
            if (asset == null) {
                asset = new ArrayList<Asset>();
            }
            return this.asset;
        }
    
        public List<Total> getTotal() {
            if (total == null) {
                total = new ArrayList<Total>();
            }
            return this.total;
        }
    
    }
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    @XmlRootElement(name = "asset")
    public class Asset {
    
        @XmlValue
        protected String content;
        @XmlAttribute(required = true)
        protected String type;
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String value) {
            this.content = value;
        }
    
        public String getType() {
            return type;
        }
    
        public void setType(String value) {
            this.type = value;
        }
    
    }
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    @XmlRootElement(name = "total")
    public class Total {
    
        @XmlValue
        protected String content;
        @XmlAttribute(required = true)
        protected String type;
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String value) {
            this.content = value;
        }
    
        public String getType() {
            return type;
        }
    
        public void setType(String value) {
            this.type = value;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.