請教下,我定義的了兩個物體類,經過序列化 獲取xml的格式如下 ,有兩個節點地方要去除 。請問在代碼中怎么去除
輸出
<?xml version="1.0" encoding="UTF-8"?>
<string ---要去除
xmlns="http://tempuri.org/">
<Response>
<ResultCode>0</ResultCode>
<ResultContent>資料獲取成功</ResultContent>
<Data>
<EUSERINFO>---要去除
<Name>張醫生</Name>
<Dept>門診部</Dept>
<BM>1001</BM>
</EUSERINFO>
</Data>
</Response>
</string>
結構
public class Response
{
[System.Xml.Serialization.XmlElement(IsNullable = true)]
[DataMember]
public string ResultCode { get; set; }
[DataMember]
public string ResultContent { get; set; }
[DataMember]
public List<EUSERINFO> Data { get; set; }
}
public class EUSERINFO
{
[System.Xml.Serialization.XmlElement(IsNullable = true)]
[DataMember]
public string Name { get; set; }
[System.Xml.Serialization.XmlElement(IsNullable = true)]
[DataMember]
public string Dept { get; set; }
[System.Xml.Serialization.XmlElement(IsNullable = true)]
[DataMember]
public string BM { get; set; }
}
public string XmlSerialize<T>(T obj)
{
XmlSerializer xs = new XmlSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
//設定序序化XML格式
XmlWriterSettings xws = new XmlWriterSettings();
xws.Indent = true;
xws.OmitXmlDeclaration = true;
xws.Encoding = Encoding.UTF8;
using (XmlWriter xtw = XmlTextWriter.Create(ms, xws))
{
XmlSerializerNamespaces _namespaces = new XmlSerializerNamespaces(
new XmlQualifiedName[] {
new XmlQualifiedName(string.Empty,string.Empty)
});
xs.Serialize(xtw, obj, _namespaces);
ms.Position = 0;
xtw.Close();
}
byte[] b = ms.ToArray();
string s = System.Text.Encoding.UTF8.GetString(b, 0, b.Length);
return s;
}
uj5u.com熱心網友回復:
[WebMethod]public string USER(string Requestparam)
{
try
{
EUSER_Request _EUSER = DESerializer<EUSER_Request>(xml1 + Requestparam);
Response _EUSER_Response = new Response();
IEnumerable<EUSERINFO> mgetEUSERINFO = _EUSER_Response.getEUSERINFO(_EUSER.UserName.Trim(), _EUSER.Dept.Trim(), _EUSER.UserCode.Trim());
if (mgetEUSERINFO == null)
{
_EUSER_Response.ResultCode = "1";// = new EUSER_Response() { ResultCode = "1", ResultContent = "資料獲取失敗", mEUSERINFO= };
_EUSER_Response.ResultContent = "資料獲取失敗";
}
else
{
_EUSER_Response.ResultCode = "0";// = new EUSER_Response() { ResultCode = "1", ResultContent = "資料獲取失敗", mEUSERINFO= };
_EUSER_Response.ResultContent = "資料獲取成功";
_EUSER_Response.Data = (List<EUSERINFO>)mgetEUSERINFO;
}
string XML = XmlSerialize(_EUSER_Response);
// string filepath = AppDomain.CurrentDomain.BaseDirectory + "User.xml";
return XML;
}
catch
{
return string.Empty;
}
}
uj5u.com熱心網友回復:
如果List<EUSERINFO> Data下有兩個EUSERINFO,你怎么辦?
uj5u.com熱心網友回復:
顯示<Data>
<Name>張醫生</Name>
<Dept>門診部</Dept>
<BM>1001</BM>
</Data>
<Data>
<Name>李醫生</Name>
<Dept>住院部</Dept>
<BM>1002</BM>
</Data>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/21176.html
標籤:ASP.NET
上一篇:詳說tcp粘包和半包
