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

  • Home
  • SEARCH
  • 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 434107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:14:26+00:00 2026-05-12T20:14:26+00:00

Sample XML. <person> <name>Joe Dirt</name> <ssn>123-45-6789</ssn> <dob>07/04/1981</dob> </person> Sample Java Class public class Person(){

  • 0

Sample XML.

<person>
  <name>Joe Dirt</name>
  <ssn>123-45-6789</ssn>
  <dob>07/04/1981</dob>
</person>

Sample Java Class

public class Person(){
  private String name;
  private String ssn;
  private java.util.Date dob;
.....
}

Sample Digester rules

<?xml version="1.0"?>
<digester-rules>
  <pattern value="message">
      <object-create-rule classname="Person" />
      <bean-property-setter-rule pattern="name" propertyname="name" />
      <bean-property-setter-rule pattern="ssn" propertyname="ssn" />
      <bean-property-setter-rule pattern="dob" propertyname="dob" />
 </pattern>
</digester-rules>
  • 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-12T20:14:27+00:00Added an answer on May 12, 2026 at 8:14 pm

    Should be able to register a DateConverter, and all should work:

    import org.apache.commons.beanutils.Converter;
    
    class MyDateConverter implements Converter {
        @Override
        public Object convert(Class clazz, Object value) {
            if (clazz.equals(Date.class)) {
                SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
                try {
                    return sdf.parse((String) value);
                } catch (ParseException pe) {
                    throw new IllegalArgumentException(pe);
                } catch (ClassCastException cce) {
                    throw new IllegalArgumentException(cce);
                }
            } else {
                throw new IllegalArgumentException("Expected Date class");
            }
        }
    }
    
    ......
    
    import org.apache.commons.beanutils.ConvertUtils;
    
    @Test
    public void testXmlRules() throws Exception {
        ConvertUtils.register(new MyDateConverter(), Date.class);
        Digester digester = DigesterLoader.createDigester(new InputSource(this
                .getClass().getResourceAsStream("rules.xml")));
        Person person = (Person) digester.parse(this.getClass()
                .getResourceAsStream("person.xml"));
        Assert.assertEquals("Joe Dirt", person.getName());
        Assert.assertEquals("123-45-6789", person.getSsn());
        Assert.assertEquals(new SimpleDateFormat("dd/MM/yyyy")
                .parse("07/04/1981"), person.getDob());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file as under <!--Sample Person Data--> <Person> <PersonDetail PersonId=1> <Name>Priyanka
class Person { public string m_name; private int m_age; // << how do I
I'm using XStream and I have an XML sample: <person> <firstname>Joe</firstname> <lastname>Walnes</lastname> <phone value=1234-456
XML sample ( original link ): <records> <record index=1> <property name=Username>Sven</property> <property name=Domain>infinity2</property> <property
I have a following XML: <person xmlns:a=http://example.com xmlns:b=http://sample.net> <a:fName>John</a:fName> <a:lName>Wayne</a:lName> <b:age>37</b:age> </person> How do
given the simple xml snipet... <workers> <worker> <name>Fred</name> <dob>19410501</dob> </worker> <worker> <name>Fred</name> <dob>19410501</dob> </worker>
I have a sample xml file which looks like the one below: <Root> <SubOne>
This is the sample xml document : <bookstore> <book category=COOKING> <title lang=english>Everyday Italian</title> <author>Giada
Please see the sample xml given below. As per a requirement, I need to
I have a bit of xml file named Sample.xml which is shown below <?xml

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.