我正在尝试创建用于跟踪XML的POJO类,其余很好,但我无法获得参数标记的值,即valueB,valueC。
我为下面的xml创建了Step,Input和Parameter pojo类,其中的参数类代码如下所示。
以下是XML:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE step SYSTEM "step.dtd">
<step>
<class>Step</class>
<description> test </description>
<input>
<parameter name="A" overwrite="yes"/>
<parameter name="B" overwrite="yes">valueB</parameter>
<parameter name="C" overwrite="yes">valueC</parameter>
</input>
</step>
Pojo课程:
public class Parameter
{
private String name;
private String parameter;
private String content;
public String getContent ()
{
return content;
}
public String setContent ()
{
return content;
}
private String overwrite;
@XmlAttribute
public String getName ()
{
return name;
}
public void setName (String name)
{
this.name = name;
}
public String getOverwrite ()
{
return overwrite;
}
public void setOverwrite (String overwrite)
{
this.overwrite = overwrite;
}
@Override
public String toString()
{
return "ClassPojo [content = "+content+",name = "+name+", overwrite = "+overwrite+", parameter="+parameter+"]";
}
}
输入类:
public class Input
{
private Parameter[] parameter;
public Parameter[] getParameter ()
{
return parameter;
}
public void setParameter (Parameter[] parameter)
{
this.parameter = parameter;
}
@Override
public String toString()
{
return "ClassPojo [parameter = "+parameter+"]";
}
}
步骤类:
@XmlRootElement(name="step")
public class Step
{
private Input input;
private String description;
private String class1;
private Output output;
public Input getInput ()
{
return input;
}
public void setInput (Input input)
{
this.input = input;
}
public String getDescription ()
{
return description;
}
public void setDescription (String description)
{
this.description = description;
}
public String getClass1 ()
{
return class1;
}
public void setClass (String class1)
{
this.class1 = class1;
}
public Output getOutput ()
{
return output;
}
public void setOutput (Output output)
{
this.output = output;
}
@Override
public String toString()
{
return "ClassPojo [input = "+input+", description = "+description+", class = "+class1+", output = "+output+"]";
}
}
答案 0 :(得分:1)
将@XmlValue添加到参数类中的内容字符串。
你还必须将@XmlAttribute添加到你的getOverwrite()方法中才能使它工作。