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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:19:23+00:00 2026-05-20T11:19:23+00:00

Assume there’s an XMLBeans XmlObject with attributes, how can I get selected attributes in

  • 0

Assume there’s an XMLBeans XmlObject with attributes, how can I get selected attributes in single step?

I’m expecting like something ….

removeAttributes(XmlObject obj, String[] selectableAttributes){};

Now the above method should return me the XMLObject with only those attributes.

  • 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-20T11:19:23+00:00Added an answer on May 20, 2026 at 11:19 am

    Assumption: the attributes that you want to remove from your XmlObject must be optional in the corresponding XML Schema. Under this assumption, XMLBeans provides you with a couple of useful methods: unsetX and isSetX (where X is your attribute name. So, we can implement a removeAttributes method in this way:

    public void removeAttributes(XmlObject obj, 
        String[] removeAttributeNames)
            throws IllegalArgumentException, IllegalAccessException,
            InvocationTargetException, SecurityException, 
            NoSuchMethodException {
        Class<?> clazz = obj.getClass();
        for (int i = 0; i < removeAttributeNames.length; i++) {
            String attrName = 
                    removeAttributeNames[i].substring(0, 1).toUpperCase() +
                    removeAttributeNames[i].substring(1);
            String isSetMethodName = "isSet" + attrName;
    
            Boolean isSet = null;
            try {
                Method isSetMethod = clazz.getMethod(isSetMethodName);
                isSet = (Boolean) isSetMethod.invoke(obj, new Object[] {});
            } catch (NoSuchMethodException e) {
                System.out.println("attribute " + removeAttributeNames[i]
                        + " is not optional");
            }
    
            if (isSet != null && isSet.booleanValue() == true) {
                String unsetMethodName = "unset" + attrName;
                Method unsetMethod = clazz.getMethod(unsetMethodName);
                unsetMethod.invoke(obj, new Object[] {});
            }
        }
    }
    

    Note 1: I have slightly modified the semantics of your method signature: the second argument (the String[]) is actually the list of attributes that you want to remove. I think this is more consistent with the method name (removeAttributes), and it also simplify things (using unsetX and isSetX).

    Note 2: The reason for calling isSetX before calling unsetX is that unsetX would throw an InvocationTargetException if called when the attribute X is not set.

    Note 3: You may want to change exception handling according to your needs.

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

Sidebar

Related Questions

Assume there exists an XML instance document that looks like this: <root> <object type=foo>
I assume there might be a HTML5 or some JS that can be used
Let's assume there is a SQL Server 2008 table like below, that holds 10
Assume there is a string hexString = 0x12 or 0x45 etc. How can I
Assume there are two models: User and Question . I can use @OneToMany to
Assume there is a document with a single input. What I'm trying to do
Let's assume there are 2 applications. The POM hierarchy might look like this: parent
I assume there must be a system and language independent way to just stick
How do I have a script run every, say 30 minutes? I assume there
Assume I have created a compiled re: x = re.compile('^\d+$') Is there a way

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.