[英]How to read and decode base64 data from XML in java
i have column data is in XML format with Base64 encryption. 我有使用Base64加密的XML格式的列数据。 Now how to read the values 现在如何读取值
<?xml version="1.0" encoding="UTF-8"?>
<event id="370e7324-3-85ec-63dac16aacb6">
<properties>
<property enc="BASE64" name="DAV:name" value="Q2FsZWmnmewqzRlYXI="/>
</properties>
</event>
and my java code is 我的java代码是
public Object readingSqlResultedRecord(ResultSet result){
try {
Query q="select xml from empdata";
String xml = result.getString(1);
System.out.println("----xml----"+xml);
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
i want read this value value="Q2FsZWmnmewqzRlYXI=" it is possible? 我想读取此值value =“ Q2FsZWmnmewqzRlYXI =”,这可能吗?
You are getting " xml " as String, which you need to convert in a DOM object to parse it easily. 您将获得“ xml ”作为字符串,您需要将其转换为DOM对象以轻松解析它。
Here are some of the links which might help you to do what you want, 以下是一些链接,这些链接可以帮助您完成自己想做的事情,
http://www.journaldev.com/1237/java-convert-string-to-xml-document-and-xml-document-to-string http://www.journaldev.com/1237/java-convert-string-to-xml-document-and-xml-document-to-string
http://www.coderanch.com/t/512978/java/java/convert-string-xml-file-java http://www.coderanch.com/t/512978/java/java/convert-string-xml-file-java
java convert string to xml and parse node java将字符串转换为xml并解析节点
in short, 简而言之,
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xmlStr)));
return doc;
Use JAXB for xml parsing. 使用JAXB进行xml解析。
@XmlRootElement(name="event")
@XmlAccessorType(value=XmlAccessType.FIELD)
public class Event
{
@XmlAttribute(name="id")
private String id;
@XmlElement(name="properties")
private Event.Properties properties;
@XmlRootElement(name="properties")
@XmlAccessorType(value=XmlAccessType.FIELD)
public static class Properties
{
@XmlElement(name="property")
private Event.Property property;
}
@XmlRootElement(name="property")
@XmlAccessorType(value=XmlAccessType.FIELD)
public static class Property
{
@XmlAttribute(name="enc")
private String enc;
@XmlAttribute(name="name")
private String name;
@XmlAttribute(name="value")
private String value;
}
}
Create corresponding getter and setter. 创建相应的getter和setter。 Then 然后
JAXBContext context = JAXBContext.newInstance(Event.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
//All the xml data will be mapped into JAXB class instance
Event event = (Event) unmarshaller.unmarshal("xml_file_path");
//get the data
String value = event.getProperties().getProperty().getValue();
String decodedValue = DatatypeConverter.parseBase64Binary(value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.