注意:  我是EclipseLink JAXB (MOXy)负责人,也是JAXB 2 (JSR-222)专家组的成员。
大多数 XML 绑定库都需要在 XML 表示中的每一级嵌套一个对象。EclipseLink JAXB (MOXy) 具有@XmlPath启用基于 XPath 的映射以消除此限制的扩展。
例子
下面是如何将@XmlPath扩展应用到您的用例的演示。
package forum10511601;
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;
@XmlRootElement(name="Example")
@XmlAccessorType(XmlAccessType.FIELD)
class Example {
    @XmlAttribute
    private String library;
    @XmlPath("book/AUTHORS_TEST/text()")
    private String authorsTest;
    @XmlPath("book/EXAMPLE_TEST/text()")
    private String exampleTest;
}
jaxb.properties
要将 MOXy 指定为您的 JAXB 提供者,您需要jaxb.properties使用以下条目添加与域模型在同一包中命名的文件(请参阅将EclipseLink MOXy 指定为您的 JAXB 提供者)。
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
演示
由于 MOXy 是 JAXB (JSR-222) 实现,因此您使用标准 JAXB 运行时 API(从 Java SE 6 开始包含在 JRE/JDK 中)。
package forum10511601;
import java.io.File;
import javax.xml.bind.*;
public class Demo {
    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Example.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        File xml = new File("src/forum10511601/input.xml");
        Example example = (Example) unmarshaller.unmarshal(xml);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(example, System.out);
    }
}
输入.xml/输出
<?xml version="1.0" encoding="UTF-8"?>
<Example library="somewhere">
   <book>
      <AUTHORS_TEST>Author_Name</AUTHORS_TEST>
      <EXAMPLE_TEST>Author_Name</EXAMPLE_TEST>
   </book>
</Example>