XML格式化输出显示_C#

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; }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值