Hi all:
I want to match some unknow elements nested some parent element where some
newly defined element might be added sometime.
The sample xml is as below:
<Class name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
method="entry">
<Parameter name="comment" index="0" type="insert"
table="MOCO_CODICMT">
<Main>
<DeviceType constant="true">pc</DeviceType>
<CheckStatus constant="true">N</CheckStatus>
<ValidCheck constant="true">Yes</ValidCheck>
<CheckDesc></CheckDesc>
<UserId>userid</UserId>
<PrimaryKey1>cmtno</PrimaryKey1>
</Main>
<SubText>
<!--<Type constant="true/false"></Type>-->
<!--<Title>title</Title>-->
<Content>contents</Content>
<WriterId>writeid</WriterId>
<WriterUserName>userid</WriterUserName>
</SubText>
</Parameter>
</Class>
The elements under <Main> and <SubText> are all variable someday, both name
and amounts. So I define a ParaItem pojo to wrap sub elements of the two
element. That means I want to create a Paraitem for every sub element
,whatever its name is, then add the object to paraent object Parameter's list
property saving all the related Paraitem.
The Paraitem source code is following:
public class ParaItem {
private String elemName;
private String argPropNameOrValue;
private boolean isConstant;
public ParaItem() {
}
public ParaItem(String elemName, String argPropNameOrValue, boolean
constant) {
this.elemName = elemName;
this.argPropNameOrValue = argPropNameOrValue;
isConstant = constant;
}
public ParaItem(String elemName, String argPropNameOrValue) {
this.elemName = elemName;
this.argPropNameOrValue = argPropNameOrValue;
}
public String getElemName() {
return elemName;
}
public String getArgPropNameOrValue() {
return argPropNameOrValue;
}
public boolean isConstant() {
return isConstant;
}
}
The Parameter source code is below:
public class Parameter {
private String index;
private String operType;
private String dataType;
private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
private List<ParaItem> listSubField =new ArrayList<ParaItem>();
public Parameter(String operType) {
this.operType = operType;
}
public List<ParaItem> getListMainFiled() {
return listMainFiled;
}
public void setListMainFiled(List<ParaItem> listMainFiled) {
this.listMainFiled = listMainFiled;
}
public List<ParaItem> getListSubField() {
return listSubField;
}
public void setListSubField(List<ParaItem> listSubField) {
this.listSubField = listSubField;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getOperType() {
return operType;
}
public void setOperType(String operType) {
this.operType = operType;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public void addMainParaItem(ParaItem pi){
getListMainFiled().add(pi);
}
public void addSubParaItem(ParaItem pi){
getListSubField().add(pi);
}
}
I suppose regex rule is the best way to make it , but googling and the
javadoc doesn't tell me how to set a regex expression for a pattern. No way
out, who knows the solotion , thanks.
Kurt