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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:15:28+00:00 2026-06-11T20:15:28+00:00

f.e. I have next xml scheme: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema targetNamespace=http://www.example.com xmlns=http://www.example.com elementFormDefault=qualified>

  • 0

f.e. I have next xml scheme:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.example.com"
        xmlns="http://www.example.com"
        elementFormDefault="qualified">

    <xs:complexType name="TItem">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="id" type="xs:int" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:element name="Resource">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="item" type="TItem" maxOccurs="unbounded" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

Based on that xsd jaxb generates java code using which I’m creating next xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Resource xmlns="http://www.example.com">
    <item id="10">asdf</item>
    <item id="2">some text</item>
    <item id="9">some item</item>
    <item id="14">vzxc</item>
</Resource>

So. I want to produce xml with sorted items by id. So it should be:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Resource xmlns="http://www.example.com">
    <item id="2">some text</item>
    <item id="9">some item</item>
    <item id="10">asdf</item>
    <item id="14">vzxc</item>
</Resource>

Is it possible with jaxb?

P.S. id is not unique – there could be a lot of items with id=”22″, etc.

  • 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-11T20:15:29+00:00Added an answer on June 11, 2026 at 8:15 pm

    Try to change your item to a TreeSet in Resource

    @XmlRootElement(name = "Resource")
    public class Resource {
        @XmlElement(required = true)
        protected Collection<TItem> item;
        ....
        public Collection<TItem> getItem() {
            if (item == null) {
                item = new TreeSet<TItem>(cmp);//cmp is an instance of Comparator<TItem>
            }
        return this.item;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have xsd schema: <?xml version=1.0 encoding=UTF-8?> <xs:schema targetNamespace=urn:v1 xmlns=urn:v1 xmlns:reg=urn:v1 xmlns:xop=http://www.w3.org/2004/08/xop/include xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault=qualified
I have the next layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=horizontal android:layout_width=fill_parent android:layout_height=wrap_content> <ImageView
I have the next element <statement id =5> insert into TBTEMPLATES(CTDB_LAST_UPDATOR) values('<?xml version=1.0 encoding=UTF-8?><Interface
I have next WSDL file <definitions targetNamespace=http://soft.com/ name=LoggingWebService xmlns=http://schemas.xmlsoap.org/wsdl/ xmlns:tns=http://ws.config.softid.softcomputer.com/ xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/> <types> <xsd:schema>
I have next xml: <page> <document> <id>1001</id> <cur>USD</cur> <date>01.01.2009</date> <amount>10</amount> </document> <document> <id>1001</id> <cur>USD</cur>
I have the next directory structure for my personal project: mines/ build.xml build/ build/classes/
I have some problems in writing down the schema of my XML file, that
I want to ask your advice in next situation. I have xml file with
Very next to XML, I've developed an XML sheet, alongside a XSD schema and
I have an XML schema with my video element and youtube element inside: <xs:element

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.