Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/augustt198/xml-mapper
Java ORM for XML parsing
https://github.com/augustt198/xml-mapper
Last synced: about 2 months ago
JSON representation
Java ORM for XML parsing
- Host: GitHub
- URL: https://github.com/augustt198/xml-mapper
- Owner: augustt198
- Created: 2014-03-07T23:22:54.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-04-06T14:50:29.000Z (almost 11 years ago)
- Last Synced: 2023-08-02T15:35:24.575Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 365 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# XML-Mapper
A Java ORM for easily parsing XML.
Uses dom4j for intermediate parsing and handling of `Documents` and `Elements`
## Example
To represent the following XML
```xml
John
Doe
```
The class `Person` could be created, using annotations to reflect values in the XML
```java
public class Person implements Mappable {@Attribute("age")
public int age;@Path("name.first")
@Text
public String firstName;@Path("name.last")
@Text
public String lastName;
}
```Values can then be assigned to the `Person` class by using the `MappingFactory`
```java
Person person = new Person();try {
person = MappingFactory.map(person, /* Your XML Element */);
} catch(MappingException e) {
e.printStackTrace();
}
```## Annotation Descriptions
#### `@Attribute(String)`
Gets the value of the attribute given.#### `@Path(String)`
Navigates through sub-elements when supplied a string in the format of `tag1.tag2.tag3...` - Should be used in conjunction with annotations that get a value from an element.#### `@Text`
Gets the value of the inner text of an element.#### `@Tag`
Gets a boolean value based on if the element exists.#### `@Required`
Marks the field as necessary to be assigned a value - will throw a `MissingRequiredFieldException` if not.## Conflicts
Not all annotations can be used in conjuction. Annotations that get a value from an element (`@Attribute`, `@Text`, `@Tag`) will throw an `IllegalAnnotationException` if used with each other.
## To Do
* Add mapping for Arrays (`[]` and `List`)
* Add ability to parse complex sub-elements defined in a `Mappable` class.