Given following XML input, how can I parse raw value of "descr" attribute?
<?xml version="1.0"?>
<declaration descr=" "/>
I tried following with JAXB and Jackson. In both cases space is printed, while I expect
 
JaxB test:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "declaration")
public class DeclarationTestJaxb {
@XmlAttribute
private String descr;
public String getDescr() {
return descr;
}
public void setDescr(String descr) {
this.descr = descr;
}
@Override
public String toString() {
return descr;
}
public static void main(String[] args) throws JAXBException {
Unmarshaller unmarshaller = JAXBContext.newInstance(DeclarationTestJaxb.class).createUnmarshaller();
System.out.println(unmarshaller.unmarshal(new File("test.xml")));
}
}
I tried the same with @JsonRawValue and @JacksonXmlProperty(isAttribute = true). However the output is still converted.
You can't. XML parsers always decode entities before returning strings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.