tags:

views:

13

answers:

1

i am parsing an xml file using the digester , where i set the subelements to the variables of the bean using the pattern

like (" root\subelements\subsubelements ","xyz");

where xyz is the variable in the bean , and how do i set the attributes of the element to the variable in the bean like that ,

I mean what is the pattern and method i need to use in order to do so ?

<student name="JavaGirl" division="B">
                <course>
                     <id>C3</id>
                    <name>EJB</name>
                 </course>
         </student>

here how do i set the name and division to the variables in the bean ?

A: 

i am parsing an xml file using the digester , where i set the subelements to the variables of the bean using the pattern

like (" root\subelements\subsubelements ","xyz");

I am not familiar with Digester, but if you are looking to do XPath based mapping this can easily be done with MOXy

@XmlPath("root/subelements/subelements")
private SomeClass xyz;

For examples see:

For your particular example you could easily use JAXB:

import javax.xml.bind.annotation.*;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Student {
    @XmlAttribute
    private String name;

    @XmlAttribute
    private String division;

    private Course course;
}

and

import javax.xml.bind.annotation.*;

@XmlAccessorType(XmlAccessType.FIELD)
public class Course {
   private String name;
   private String id;
}
Blaise Doughan