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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:58:24+00:00 2026-06-09T13:58:24+00:00

I have the following xml string. I want to convert it in to a

  • 0

I have the following xml string. I want to convert it in to a java object, to map each tag with the fields of that object. Its better that if I can introduce different field names compared to tag name. How I can do that? I am looking on JAXB but I am still confused about parts like “ns4:response” and tags within tags. Thank you in advance…

<ns4:response>
    <count>1</count>
    <limit>1</limit>
    <offset>1</offset>
    <ns3:payload xsi:type="productsPayload">
        <products>
            <product>
                <avgRating xsi:nil="true"/>
                <brand>Candie's</brand>
                <description>
                    <longDescription>
                    long descriptions
                    </longDescription>
                    <shortDescription>
                    short description
                    </shortDescription>
                </description>
                <images>
                    <image>
                        <altText>alternate text</altText>
                        <height>180.0</height>
                        <url>
                        url
                        </url>
                        <width>180.0</width>
                    </image>
                </images>
                <price>
                    <clearancePrice xsi:nil="true"/>
                    <regularPrice xsi:nil="true"/>
                    <salePrice>28.0</salePrice>
                </price>
            </product>
        </products>
    </ns3:payload>
</ns4:response>
  • 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-09T13:58:25+00:00Added an answer on June 9, 2026 at 1:58 pm

    JAXB is the Java standard (JSR-222) for converting objects to/from XML. The following should help:

    Unmarshalling from a String

    You will need to wrap the String in an instance of StringReader before your JAXB impl can unmarshal it.

    StringReader sr = new StringReader(xmlString);
    JAXBContext jaxbContext = JAXBContext.newInstance(Response.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    Response response = (Response) unmarshaller.unmarshal(sr);
    

    Different Field and XML Names

    You can use the @XmlElement annotation to specify what you want the name of the element to be. By default JAXB looks at properties. If you wish to base the mappings on the fields then you need to set @XmlAccessorType(XmlAccessType.FIELD).

    @XmlElement(name="count")
    private int size;
    

    Namespaces

    The @XmlRootElement and @XmlElement annotations also allow you to specify namespace qualification where needed.

    @XmlRootElement(namespace="http://www.example.com")
    public class Response {
    }
    

    For More Information

    • http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
    • http://blog.bdoughan.com/2012/07/jaxb-and-root-elements.html
    • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following string that I want to convert to a presentable XML
I have XML content in a string that defines its encoding in its declaration.
I am struggling with the following issue: I have an XML string that contains
I want to convert a org.w3c.dom.Document object to a String. I'm using Java 6
I have the following string: <?xml version=1.0 encoding=utf-8?> <string xmlns=http://tempuri.org/UKash/Service1><UKashTransaction><txCode>99</txCode><txDescription>Failed</txDescription><settleAmount> <settleAmount><transactionId>1341481253EDFC871620</transactionId><changeIssueVoucherNumber> <changeIssueVoucherNumber><changeIssueVoucherCurr> <changeIssueVoucherCurr><changeIssueAmount> <changeIssueAmount><changeIssueExpiryDate>
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have the following contents in my XML file: <items> <item id=1><content><![CDATA[<p>string</p>]]></content></item> </items> I
I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE web.xml
I have following xml and I want to fetch the value of node which
I have following XML, and i wish to save its data in my SQL

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.