C# 复杂格式XML转实体
标签:log version data 系统 openid eof gid mil attribute
注意自己的数据结构
实体类如下:
//[Serializable] // 表示该类可以被序列化
[XmlRoot("xml")] // 设置为XML中的根元素名称
///
/// 事件推送群发结果
///
public class ResponseMassSendJobFinish : ResponseReceivingEvent
{
///
/// 群发的消息ID
///
public long MsgID { get; set; }
///
/// 群发的结果,为“send success”或“send fail”或“err(num)”。
/// 但send success时,也有可能因用户拒收公众号的消息、系统错误等原因造成少量用户接收失败。
/// err(num)是审核失败的具体原因,可能的情况如下: err(10001), //涉嫌广告 err(20001),
/// //涉嫌政治 err(20004), //涉嫌社会 err(20002),
/// //涉嫌色情 err(20006), //涉嫌违法犯罪 err(20008),
/// //涉嫌欺诈 err(20013), //涉嫌版权 err(22000),
/// //涉嫌互推(互相宣传) err(21000), //涉嫌其他 err(30001)
/// // 原创校验出现系统错误且用户选择了被判为转载就不群发 err(30002)
/// // 原创校验被判定为不能群发 err(30003) // 原创校验被判定为转载文且用户选择了被判为转载就不群发
///
public string Status { get; set; }
///
/// tag_id下粉丝数;或者openid_list中的粉丝数
///
public int TotalCount { get; set; }
///
/// 过滤(过滤是指特定地区、性别的过滤、用户设置拒收的过滤,用户接收已超4条的过滤)后,准备发送的粉丝数,原则上,FilterCount 约等于 SentCount + ErrorCount
///
public long FilterCount { get; set; }
///
/// 发送成功的粉丝数
///
public long SentCount { get; set; }
///
/// 发送失败的粉丝数
///
public long ErrorCount { get; set; }
[XmlElement("CopyrightCheckResult")]
public CopyrightCheckResultData CopyrightCheckResult { get; set; }
[XmlElement("ArticleUrlResult")]
public ArticleUrlResultData ArticleUrlResult { get; set; }
/////
///// 整体校验结果
/////
//public string CheckState { get; set; }
/////
///// 1-未被判为转载,可以群发,2-被判为转载,可以群发,3-被判为转载,不能群发
/////
/////public string CheckState { get; set; }
/////
///// 群发文章的url
/////
//public string ArticleUrl { get; set; }
}
[XmlType(TypeName = "CopyrightCheckResult")]
public class CopyrightCheckResultData
{
public long Count { get; set; }
[XmlElement("ResultList")]
///
/// 各个单图文校验结果
///
public ResultListData ResultList { get; set; }
///
/// 1-未被判为转载,可以群发,2-被判为转载,可以群发,3-被判为转载,不能群发
///
public int CheckState { get; set; }
}
public class ResultListData
{
[XmlElement("item")]//这里是个重点
public List- item { get; set; }
}
public class Item
{
[XmlElement("ArticleIdx")]
///
/// 群发文章的序号,从1开始
///
public int ArticleIdx { get; set; }
[XmlElement("UserDeclareState")]
///
/// 用户声明文章的状态
///
public int UserDeclareState { get; set; }
[XmlElement("AuditState")]
///
/// 系统校验的状态
///
public int AuditState { get; set; }
[XmlElement("OriginalArticleUrl")]
///
/// 相似原创文的url
///
public string OriginalArticleUrl { get; set; }
[XmlElement("OriginalArticleType")]
///
/// 相似原创文的类型
///
public string OriginalArticleType { get; set; }
[XmlElement("CanReprint")]
///
/// 是否能转载
///
public int CanReprint { get; set; }
[XmlElement("NeedReplaceContent")]
///
/// 是否需要替换成原创文内容
///
public long NeedReplaceContent
{
get;
set;
}
[XmlElement("NeedShowReprintSource")]
///
/// 是否需要注明转载来源
///
public long NeedShowReprintSource { get; set; }
}
public class ArticleUrlResultData
{
public long Count { get; set; }
[XmlElement("ResultList")]
public ResultListNode ResultList { get; set; }
}
public class ResultListNode
{
[XmlElement("item")]
public List item { get; set; }
}
public class ResultListItem
{
[XmlAttribute]
///
/// 群发文章的序号,从1开始
///
public long ArticleIdx { get; set; }
[XmlAttribute]
///
/// 群发文章的url
///
public string ArticleUrl { get; set; }
}
xml 数据如下
xml>
ToUserName>gh_7]]>ToUserName>
FromUserName>oU9K7]]>FromUserName>
CreateTime>1576291902CreateTime>
MsgType>event]]>MsgType>
Event>MASSSENDJOBFINISH]]>Event>
MsgID>314748MsgID>
Status>err(30003)]]>Status>
TotalCount>0TotalCount>
FilterCount>0FilterCount>
SentCount>0SentCount>
ErrorCount>0ErrorCount>
CopyrightCheckResult>
Count>1Count>
ResultList>
item>
ArticleIdx>1ArticleIdx>
UserDeclareState>0UserDeclareState>
AuditState>2AuditState>
OriginalArticleUrl>http://mp.weixin.qq.com/s?__biz=MzU5Nzk1MDgwNA==#rd]]>OriginalArticleUrl>
OriginalArticleType>1OriginalArticleType>
CanReprint>1CanReprint>
NeedReplaceContent>1NeedReplaceContent>
NeedShowReprintSource>1NeedShowReprintSource>
item>
ResultList>
CheckState>2CheckState>
CopyrightCheckResult>
ArticleUrlResult>
Count>0Count>
ResultList>ResultList>
ArticleUrlResult>
xml>
///
/// 反序列化
///
///
///
///
public static T Deserialize(Stream stream)
{
XmlSerializer xmldes = new XmlSerializer(typeof(T));
return (T)xmldes.Deserialize(stream);
}
//使用
FileStream fs = new FileStream(path, FileMode.Open);
var data = EntityHelper.Deserialize(fs);
结果如图:
C# 复杂格式XML转实体
标签:log version data 系统 openid eof gid mil attribute
原文地址:https://www.cnblogs.com/Mr-lin66/p/12040384.html
评论