我怎样才能得到<;b>;从xml到java的价值

我怎样才能得到<;b>;从xml到java的价值,java,xml,jaxb,Java,Xml,Jaxb,及 这是我的两门课 package entities; import javax.xml.bind.annotation.*; @XmlRootElement(name="b") public class Bcontent { private String content; @XmlValue public String getContent() { return content; } public void setContent(

这是我的两门课

package entities;

import javax.xml.bind.annotation.*;

@XmlRootElement(name="b")
public class Bcontent {
    private String content;

    @XmlValue
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Bcontent(String content) {
        super();
        this.content = content;
    }

    public Bcontent() {
        super();
    }
它将工作,但“测试b标签”将消失

对不起,我的英语不好


谢谢你。从实体类中删除XML注释

2。读取标签数据

比如说:

    private Bcontent bcontent;

    @XmlElement(name="b")
    public Bcontent getBcontent() {
        return bcontent;
    }
    public void setBcontent(Bcontent bcontent) {
        this.bcontent = bcontent;
    }
SAXReader=newsaxreader();
文档=reader.read(文件);
List nodes=document.selectNodes(“/pdf2xml/page/text”);
用于(节点:节点){
System.out.println(“值:”+node.selectSingleNode(“b”).getText());
}
Maven依赖项:

SAXReader reader = new SAXReader();
Document document = reader.read(file);

List<Node> nodes = document.selectNodes("/pdf2xml/page/text");

for (Node node : nodes) {
    System.out.println("value : " + node.selectSingleNode("b").getText());
}

杰克森
杰克森
1.1.6
dom4j
dom4j
1.6.1

您确定JAXB是该任务的正确技术吗?我认为xml数据是非常动态的。可能是SAX或DOM解析器会更好?xpath:
/pdf2xml/page/text/b
好的,我会尝试一下,谢谢:)我使用了xpath,但它不起作用“1个IllegaAnnotationExceptions计数”再次@evgenylebeDevanotation for entity类不需要xpath解决方案
    private Bcontent bcontent;

    @XmlElement(name="b")
    public Bcontent getBcontent() {
        return bcontent;
    }
    public void setBcontent(Bcontent bcontent) {
        this.bcontent = bcontent;
    }
SAXReader reader = new SAXReader();
Document document = reader.read(file);

List<Node> nodes = document.selectNodes("/pdf2xml/page/text");

for (Node node : nodes) {
    System.out.println("value : " + node.selectSingleNode("b").getText());
}
<dependency>
    <groupId>jaxen</groupId>
    <artifactId>jaxen</artifactId>
    <version>1.1.6</version>
</dependency>

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>