private void button49_Click(object sender, EventArgs e)
{
txt_Item_Number.BackColor = Color.White;
txt_RequestId.BackColor = Color.White;
if (string.IsNullOrEmpty(txt_Item_Number.Text))
{
MessageBox.Show("单号未填写!");
txt_Item_Number.BackColor = Color.Red;
return;
}
string EZUrlresult = LUX_getStrEZGPURL(txt_Item_Number.Text.Trim());
if (string.Compare(EZUrlresult.Split('|').FirstOrDefault(),Boolean.TrueString,true)!=0)
{
MessageBox.Show(EZUrlresult.Split('|')[1]);
return;
}
if (string.IsNullOrEmpty(txt_RequestId.Text))
{
MessageBox.Show("RequestId为空!");
txt_RequestId.BackColor = Color.Red;
return;
}
//获取josn数据
string url = $"http://oa.abcenter.xyz/luxshare/workflow/itfw/it001/it001_nodeoperation.jsp?operation=checkPLMxml&requestid={txt_RequestId.Text}";
lnk_OAXmlLink.Text = url;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
OAXmlObj oAXmlObj = new OAXmlObj();
using (Stream resStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(resStream, Encoding.UTF8);
string respText = reader.ReadToEnd();
oAXmlObj = Newtonsoft.Json.JsonConvert.DeserializeObject<OAXmlObj>(respText);
resStream.Close();
}
if (string.IsNullOrEmpty(oAXmlObj.result))
{
oAXmlObj.result = "未获取到xml。";
return;
}
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(System.Net.WebUtility.HtmlDecode(oAXmlObj.result));//html实体解码
//格式化。缩进显示
System.IO.StringWriter sw = new System.IO.StringWriter();
using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(sw))
{
writer.Indentation = 2; // the Indentation
writer.Formatting = System.Xml.Formatting.Indented;
doc.WriteContentTo(writer);
writer.Close();
}
rtxt_OAXml.Text = System.Net.WebUtility.HtmlDecode(sw.ToString());//输出格式化xml字符串
}
private void lnk_OAXmlLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(lnk_OAXmlLink.Text);
}
public class OAXmlObj
{
public string result { get; set; }
}
XML格式化输出显示_C#
最新推荐文章于 2023-02-12 23:00:18 发布