Str converted to xml file Object Object

A, xml format

<?xml version="1.0" encoding="utf-8" ?>

<Data>

<Row>

<MyDataSource>

<driverClassName></driverClassName>

<url></url>

<userName></userName>

<password></password>

</MyDataSource>

<MySourceSql>

</MySourceSql>

<TerminalSource>

<driverClassName></driverClassName>

<url></url>

<userName></userName>

<password></password>

</TerminalSource>

<TerminaSql>

</TerminaSql>

</Row>

</Data>

 

 

@XmlAccessorType(XmlAccessType.FIELD)

@XmlRootElement(name="Data")

public class Data {

@XmlElement(name = "Row")

    private List<Row> rowList;

@Override

    public String toString() {

       return "Data{" +"rowList=" + rowList +'}';

}

    public List<Row> getRowList() {

         eturn rowList;

    }

     public void setRowList(List<Row> rowList) {

         this.rowList = rowList;

    }

}

 

two,

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;


Object convertXmlStrToObject static public (Class clazz, String xmlStr) throws Exception { 
Object xmlObject = null;

The JAXBContext context to JAXBContext.newInstance = (clazz);
// be converted to the object Xml core interface
the Unmarshaller Unmarshaller context.createUnmarshaller = ();
the StringReader = the StringReader new new SR (xmlStr);
xmlObject = Unmarshaller.unmarshal (SR);

return xmlObject;
}

 

Guess you like

Origin www.cnblogs.com/liveinpresent/p/11627493.html