浏览 2039 次
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-09-30
i try to use JAXB to binding the XML data to class. and i met some question that really boring.
the key of the question is : when i use the JAXB to get the xml data. the boolean data which in the in the created object is not correct. here are my dtd file and xml file. conditions.dtd : <!ELEMENT conditions (condition*)> <!ELEMENT condition (entrytype,type,leastNum,auto,unit,originate,last) > <!ELEMENT entrytype (#PCDATA)> <!ELEMENT type (#PCDATA)> <!ELEMENT originate (#PCDATA)> <!ELEMENT auto (#PCDATA)> <!ELEMENT unit (#PCDATA)> <!ELEMENT leastNum (#PCDATA)> <!ELEMENT last (#PCDATA)> <!ATTLIST condition isInfoComplete CDATA "true"> conditions.xml : <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE conditions SYSTEM "conditions.dtd"><conditions> <condition isInfoComplete="true"> <entrytype>blogentry</entrytype> <type>apply</type> <leastNum>3</leastNum> <auto>true</auto> <unit>week</unit> <originate>true</originate> <last>y</last> </condition> <condition isInfoComplete="true'"> <entrytype>blogentry</entrytype> <type>keep</type> <leastNum>20</leastNum> <auto>true</auto> <unit>month</unit> <originate>false</originate> <last>m</last> </condition> </conditions> the class file is generated by the JAXB tool. and follow is my test class. notice the pakage path. CollectionTest.java:public class ConditionTest { public static void main(String[] args) { try { JAXBContext jc = JAXBContext.newInstance("test.xmlparse"); Unmarshaller u = jc.createUnmarshaller(); Conditions conds = (Conditions) u.unmarshal(new FileInputStream( new File("conditions.xml"))); List cond=conds.getCondition(); int size = cond.size(); for(int i=0;i<size;i++) { Condition con=(Condition) cond.get(i); print(con); } System.out.println(conds.getCondition().size()); } catch (Exception ex) { System.out.println(ex.getMessage()); System.out.println(ex.getCause()); } } private static void print(Condition con) { System.out.println("auto:"+con.getAuto()+"\nlast:"+con.getLast()+"\nentrytype:"+con.getEntrytype()+"\ntype:"+ con.getType()+"\nunit:"+con.getUnit()+"\nisInfoComplete:"+con.getisInfoComplete()+ "\nleastNum:"+con.getLeastNum()+"\noriginate:"+con.getOriginate()+"\n\n\n"); } } here is my result: auto:true last:y entrytype:blogentry type:apply unit:week isInfoComplete:false leastNum:3 originate:true auto:true last:m entrytype:blogentry type:keep unit:month isInfoComplete:false leastNum:20 originate:false ----------------------------------------------------------------------- i tracked the program. the value of isInfoComplete have get when the object created.but the value is not correct.:twisted: 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-10-16
the reason i have find .it is caused by the dtd file is not work when the condition.java file to been created .
|
|
返回顶楼 | |