I have a XML response from REST API like below :
<?xml version="1.0" encoding="UTF-8"?>
<ns2:testpla xmlns:ns2="http:xyz" xmlns:ns7="xyz">
<ns2:category term="Default Category" value="Default Category Value"/>
<ns2:testase ns7:resource="https://www.cyz.com" units="PH"
href="ww.com">XYZ</ns2:testase>
<ns2:testase ns7:resource="https://ww.cyz.com" units="LH"
href="ww.org">AZ</ns2:testase>
<com.abc xmlns="http://lq.net" extensionDisplayName="QWZ-KEY-TP-TEST-ZWE-
TI">
<div xmlns="http://www.w3.org/1999/xhtml">TriggerA ND confirm the
functionality</div>
</com.abc>
</ns2:testpla>
I know how to get the xml element value ie"XYZ"using jaxb and bind to bean. But I'm stuck on know how to fetch the value of resource(ie;" https://www.cyz.com "),units("PH"),href("ww.com"),value of xmlns inside div ?And then to map the value to object property. Please help me.
create the separate two classes for testpla and testase
Testpla.java
@XmlRootElement(name = "ns2:testpla")
public class Testpla {
private Testase testase;
public Testase getTestase() {
return testase;
}
@XmlElement(name = "ns2:testase")
public void setTestase(Testase testase) {
this.testase = testase;
}
}
Testase.java
@XmlRootElement(name = "ns2:testase")
public class Testase {
private String resource;
private String units;
public String getResource() {
return resource;
}
@XmlAttribute(name = "ns7:resource")
public void setResource(String resource) {
this.resource = resource;
}
public String getUnits() {
return units;
}
@XmlAttribute(name = "units")
public void setUnits(String units) {
this.units = units;
}
}
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.