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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:09:51+00:00 2026-06-17T05:09:51+00:00

Here’s a trivial excerpt from my XSD file <?xml version=1.0 encoding=UTF-8?> <schema xmlns=http://www.w3.org/2001/XMLSchema targetNamespace=ns

  • 0

Here’s a trivial excerpt from my XSD file

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

  <element name="document">
        <attribute name="title" use="required"/>
  </element>
</schema>

I use the maven-jaxb2-plugin to generate Java classes from this. The Document class has a getTitle() method to return the text of the title attribute.

I want to add an additional method to Document:

public String getStrippedTitle() {
   return getTitle().replaceAll("\\s+", "");
}

I want my extra method to appear on the unmarshalled object (rather than me just calling it or writing a wrapper class) because I want to pass the top-level unmarshalled object off to a string template and have it iterate over sub-elements calling my extra method.

I found instructions but they tell me to set a property on the Unmarshaller and my (Mac OS X, Java 7) implementation doesn’t appear to support any properties.

How should I do this?

  • 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-17T05:09:52+00:00Added an answer on June 17, 2026 at 5:09 am

    Following the link the Brian Henry gave, I found I could perform binding customization inline in my schema file to do what I wanted. The effect is exactly the same as Brian’s solution, but it doesn’t require a reference to a reference to com.sun.xml.internal.

    First, the schema file gets modified somewhat:

    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="ns"
        xmlns:tns="sns" elementFormDefault="qualified"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:version="2.0">
    
      <element name="document">
          <annotation>
              <appinfo>
                  <jaxb:class implClass="DocumentEx" />
              </appinfo>
          </annotation>
          <attribute name="title" use="required"/>
      </element>
    </schema>
    

    When the schema gets compiled into Java code, the generated ObjectFactory will refer to DocumentEx instead of Document. DocumentEx is a class I create, which looks like this:

    public class DocumentEx extends Document {
       public String getStrippedTitle() {
           return getTitle().replaceAll("\\s+", "");
       }
    }
    

    Document (the class I’m extending) is still generated by the schema-to-Java compiler. Now when I unmarshall a document I actually get a DocumentEx object:

        JAXBContext jaxbContext = JAXBContext.newInstance("com.example.xml");
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setSchema(testSchema);
        DocumentEx doc = (DocumentEx)unmarshaller.unmarshal(xmlFile);
    

    There is some (hard-to-parse) documentation for this at Oracle and some helpful examples at O’Reilly.

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

Sidebar

Related Questions

here is the site : http://www.notrepanorama.com at the bottom left, i use a jquery
Here is what's going on: http://www.youtube.com/watch?v=zVEftCJ2F_U&feature=youtu.be Here is the code: extend: 'Ext.container.Viewport', alias: 'widget.viewport',
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Here's the link: www.mchenry.edu/maps/google.asp Why won't the location balloon display correctly? Also, the pop-up
Here is my query: select word_id, count(sentence_id) from sentence_word group by word_id having count(sentence_id)
Here's my .htaccess file: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule .*
Here's the two scenarios. We are using a manually built xml soap request with

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.