我正在尝试使用c#类创建一个XMl请求。
预期的输出是
<UserRequest>
<action>manage</action>
<create>
<name>Companies</name>
<item>
<symbol>GOOG</symbol>
<item />
</create>
</UserRequest>
当我使用XMl属性创建如下所示的类时
[XmlRoot("WorkflowRequest")]
public class UserRequest : RequestBase
{
public string action { get; set; }
[XmlElement("create")]
public Create create { get; set; }
}
[XmlType(AnonymousType = true)]
public class Create
{
public string name { get; set; }
[XmlElement("item")]
public Item item { get; set; }
}
[XmlType(AnonymousType = true)]
public class Item
{
public string symbolType;
public string symbol;
public string qty;
public string purchasePrice;
public string purchaseCost;
public string purchaseDate;
public string putOrCall;
public string strikePrice;
public string expirationDate;
}
和
Item symbolInfo = new Item();
symbolInfo.symbol = "GOOG";
Create ct = new Create()
{
name = "Companies",
item = symbolInfo
};
UserRequest userRequest = new UserRequest()
{
action = "manage",
create = ct
};
我得到一个奇怪的请求与item标签而不是GOOG ..有人可以指导我做错的地方这就是我得到的..
<UserRequest>
<action>manage</action>
<create>
<name>Companies</name>
<item />
</create>
</UserRequest>
[XmlType(AnonymousType = true)]
public class Item
{
[XmlElement("symbol")]
public string symbol;
//other properties
}