这是课程定义:
[Serializable()]
public class BaseClass
{
public SYSMessage SYSMessage { get; set; }
}
[Serializable()]
public class SYSMessage
{
public string messageGuid { get; set; }
}
这就是我尝试获取serml xml string的方法;
public void xmlSerializer()
{
XmlSerializer xsSubmit = new XmlSerializer(typeof(BaseClass));
var subReq = new BaseClass();
var result = "";
using (var sww = new StringWriter())
{
using (XmlWriter writer = XmlWriter.Create(sww))
{
xsSubmit.Serialize(writer, subReq);
result = sww.ToString();
}
}
}
这是结果;
<?xml version="1.0" encoding="utf-16"?>
<BaseClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SYSMessage>
<messageGuid>Test Value</messageGuid>
</SYSMessage>
</BaseClass>
但这就是我需要它的方式;
...
<SYSMessage>
<messageGuid value="Test Value" />
</SYSMessage>
...