我想使用jaxb解析xml字符串。實際上,我需要提取文字中的十進制值。使用jaxb解析xml字符串
這就是XML字符串:
<results>
<result>
<binding name="value">
<literal datatype="http://www.w3.org/2001/XMLSchema#decimal">369.0</literal>
</binding>
</result>
</results>
我有一個Java類結果:
package client;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Results {
@XmlElement
String result;
@XmlElement
Double binding;
@XmlElement
Double literal;
public Double getLiteral()
{
return literal;
}
public Double geBinding()
{
return binding;
}
public String getResult()
{
return result;
}
}
當我試圖打印的價值,我越來越空。所以我如何獲得文字標籤之間的十進制值?
Results re=(Results) JAXBContext.newInstance(Results.class)
.createUnmarshaller()
.unmarshal(new StringReader(my_xml));
System.out.println(re.getLiteral());