Assume there’s an XMLBeans XmlObject with attributes, how can I get selected attributes in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Assumption: the attributes that you want to remove from your
XmlObjectmust be optional in the corresponding XML Schema. Under this assumption, XMLBeans provides you with a couple of useful methods:unsetXandisSetX(whereXis your attribute name. So, we can implement aremoveAttributesmethod in this way: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 (usingunsetXandisSetX).Note 2: The reason for calling
isSetXbefore callingunsetXis thatunsetXwould throw anInvocationTargetExceptionif called when the attributeXis not set.Note 3: You may want to change exception handling according to your needs.