[size=18]i try to use JAXB to binding the XML data to class. and i met some question that really boring. :twisted:
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.[/size]
[size=18][color=yellow]conditions.dtd :[/color][/size]
<!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">
[size=24][color=yellow]conditions.xml :[/color][/size]
<?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:[color=red]false[/color]
leastNum:3
originate:true
auto:true
last:m
entrytype:blogentry
type:keep
unit:month
isInfoComplete:[color=red]false[/color]
leastNum:20
originate:false
-----------------------------------------------------------------------
[color=blue][size=18]i tracked the program. the value of isInfoComplete have get when the object created.but the value is not correct.[/size][/color]:twisted: :arrow:
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.[/size]
[size=18][color=yellow]conditions.dtd :[/color][/size]
<!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">
[size=24][color=yellow]conditions.xml :[/color][/size]
<?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:[color=red]false[/color]
leastNum:3
originate:true
auto:true
last:m
entrytype:blogentry
type:keep
unit:month
isInfoComplete:[color=red]false[/color]
leastNum:20
originate:false
-----------------------------------------------------------------------
[color=blue][size=18]i tracked the program. the value of isInfoComplete have get when the object created.but the value is not correct.[/size][/color]:twisted: :arrow: