xmlbean

xmlbean 使用过程中要注意问题
http://blog.csdn.net/zmhinzaghi/article/details/5752388
二 如果使用eclipse,jbuilder 工具,建立新的工程,建立src,classes,lib 等目录,将解压后的目录下的/lib/xbean.jar,/lib/jsr173_1.0.jar , /lib/resolver.jar 加入工程的build path
知原可排大PaymentResultDocument resultDoc =PaymentResultDocument.Factory.parse(fileName);
PaymentResult paymentresukt =  resultDoc.getPaymentResult();类名不同项目具体变

String result="<RESULT><ITEM><ID>JF1001</ID><NAME>张江机房</NAME> <TYPE>中心机房</TYPE> <ADDRESS>金科路</ADDRESS><X></X> <Y></Y><URL>Images/1.jpg</URL> <DES>无</DES></ITEM></RESULT>";


String result="<RESULT>" +
"<ITEM>" +
"<ID> JG1001</ID>" +
"<NAME>机柜A</NAME> " +
"<TYPE>服务器机柜</TYPE>" +
"<ADDRESS>MR1001</ADDRESS>" +
"<URL>Images/1.jpg</URL>" +
"<DES></DES>" +
" </ITEM>" +
"<ITEM>" +
"<ID> JG1002</ID>" +
"<NAME>机柜A</NAME> " +
"<TYPE>服务器机柜</TYPE>" +
"<ADDRESS>MR1001</ADDRESS>" +
"<URL>Images/2.jpg</URL>" +
"<DES></DES>" +
"</ITEM>" +
" </RESULT>";


String result="<RESULT>" +
"<ITEM>" +
"<ID>GQ1001</ID>" +
"<STARTADDRESS>金科路1号</STARTADDRESS>" +
"<ENDADDRESS>金科路1000号</ENDADDRESS>" +
"<TYPE></TYPE>" +
"<URL>Images/3.jpg</URL>" +
"<DES></DES>" +
"</ITEM>" +
"<ITEM>" +
"<ID>GQ1002</ID>" +
"<STARTADDRESS>金科路1号</STARTADDRESS> " +
"<ENDADDRESS>金科路1000号</ENDADDRESS>   " +
"<TYPE></TYPE>" +
"<URL>Images4.jpg</URL>" +
"<DES></DES>" +
"</ITEM>" +
"</RESULT>";




<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="RESULT">
<xs:complexType>
<xs:sequence>
<xs:element name="ITEM" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:string" />
<xs:element name="NAME" type="xs:string" />
<xs:element name="TYPE" type="xs:string" />
<xs:element name="ADDRESS" type="xs:string" />
<xs:element name="X" type="xs:string" />
<xs:element name="Y" type="xs:string" />
<xs:element name="URL" type="xs:string" />
<xs:element name="DES" type="xs:string" />
<xs:element name="STARTADDRESS" type="xs:string" />
<xs:element name="ENDADDRESS" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


maxOccurs="unbounded">  list  size 做准备



@Transient
public static List<MacRoom> palseXml(String xml){

List<MacRoom> list = new ArrayList<MacRoom>();
String result="<RESULT><ITEM><ID>JF1001</ID><NAME>张江机房</NAME> <TYPE>中心机房</TYPE> <ADDRESS>金科路</ADDRESS><X></X> <Y></Y><URL>Images/1.jpg</URL> <DES>无</DES></ITEM></RESULT>";
if(StringUtils.isNotBlank(result)){
try {
RESULTDocument resultDoc =RESULTDocument.Factory.parse(result);
RESULT root= resultDoc.getRESULT();

if(root!=null){
ITEM[] items= root.getITEMArray();
if(items!=null||items.length>0){
for(int i =0;i<items.length;i++){
MacRoom macroom = new MacRoom();
ITEM item =items[i];

macroom.setJfid(item.getID());
list.add(macroom);

}

}


}


} catch (XmlException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}

return list;

}

你可能感兴趣的:(xmlbean)