xml转实体类
xml 如下<content>
<head>
<callSystem>1111</callSystem>
</head>
<body>
<paramInfo>
<paramCode>Id</paramCode>
<paramValue>
<value>1</value>
</paramValue >
</paramInfo>
<paramInfo>
<paramCode>sex</paramCode>
<paramValue>
<value>2</value>
</paramValue >
</paramInfo>
</body>
</content>
实体类
public class AA
{
public string Id{get;set;}
public string sex{get;set;}
}
要怎么写才能把xml的值转成实体类 --------------------编程问答-------------------- 反序列化 序列化 --------------------编程问答-------------------- 补充一点xml是Webservice的形式传过来的 --------------------编程问答-------------------- 推荐看看linq to xml, 很好用。语句简单那。 --------------------编程问答-------------------- 求个大概的例子. --------------------编程问答--------------------
--------------------编程问答-------------------- 要是用 XMLDocument 怎么读出来? --------------------编程问答-------------------- XElement这个有Load? --------------------编程问答-------------------- 求大神用XMLDocument 给个例子看一下. --------------------编程问答--------------------
XElement root = XElement.Load(xml);
AA aa = new AA();
IEnumerable<XElement> result = from el in root.Elements("body").Elements("paramInfo") select el;
foreach (XElement xe in result)
{
if(xe.Element("paramCode").Value == "Id")
{
aa.Id = xe.Element("paramValue").Value
}
else if(xe.Element("paramCode").Value == "sex")
{
aa.sex = xe.Element("paramValue").Value
}
}
没得我骗你的 --------------------编程问答-------------------- 可以直接序列化成实体,但是实体和你的XML 结构要一样,
还有一种方式应该可行 用dynamic --------------------编程问答--------------------
XElement这个有Load?
XElement root = XElement.Load(xml);
AA aa = new AA();
IEnumerable<XElement> result = from el in root.Elements("body").Elements("paramInfo") select el;
foreach (XElement xe in result)
{
if(xe.Element("paramCode").Value == "Id")
{
aa.Id = xe.Element("paramValue").Value
}
else if(xe.Element("paramCode").Value == "sex")
{
aa.sex = xe.Element("paramValue").Value
}
}
没得我骗你的
可以直接序列化成实体,但是实体和你的XML 结构要一样,
还有一种方式应该可行 用dynamic
补充:.NET技术 , ASP.NET