• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#解析Xml格式的字符串

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Xml;

namespace ConsoleApplication4
{
    internal class Program
    {
        private static void Main()
        {
            const string xmlStr = @"<request type=""sync"" key=""1BF500B4158DBF04BA3045ABB38EAF0F"">
                                <host prod=""E10"" ver=""1.0.0.0"" ip=""192.168.11.17""  />
                                <service prod=""MES"" name=""lot.create"" />
                                <payload>
                                    <param key=""std_data"" type=""xml"">
                                        <data_request>
                                            <datainfo>
                                                <parameter key=""lot_data"" type=""data"">
                                                    <data name=""W304_DISPATCH_LIST"" cnt=""3"" tt_cnt=""0"" page=""0"" tt_page=""0"">
                                                        <row seq=""1"">
                                                            <field name=""disp_no"" type=""string"">5X11-170716001</field>
                                                            <field name=""disp_seq"" type=""numeric"">1</field>
                                                            <field name=""wo_no"" type=""string"">5101-17060800003</field>
                                                            <field name=""qty"" type=""numeric"">1890.000000</field>
                                                            <field name=""dpm_lot_no"" type=""string""/>
                                                            <field name=""workstation_no"" type=""string"">106</field>
                                                            <field name=""so_no"" type=""string"">GA-1707007-9-1</field>
                                                            <field name=""plan_start_date"" type=""date"">19000101000000000</field>
                                                            <field name=""plan_finish_date"" type=""date"">19000101000000000</field>
                                                        </row>
                                                        <row seq=""2"">
                                                            <field name=""disp_no"" type=""string"">5X11-170716001</field>
                                                            <field name=""disp_seq"" type=""numeric"">2</field>
                                                            <field name=""wo_no"" type=""string"">5101-17042200630</field>
                                                            <field name=""qty"" type=""numeric"">528.000000</field>
                                                            <field name=""dpm_lot_no"" type=""string""/>
                                                            <field name=""workstation_no"" type=""string"">106</field>
                                                            <field name=""so_no"" type=""string"">GA-1705002-2-1</field>
                                                            <field name=""plan_start_date"" type=""date"">19000101000000000</field>
                                                            <field name=""plan_finish_date"" type=""date"">19000101000000000</field>
                                                        </row>
                                                        <row seq=""3"">
                                                            <field name=""disp_no"" type=""string"">5X11-170716001</field>
                                                            <field name=""disp_seq"" type=""numeric"">3</field>
                                                            <field name=""wo_no"" type=""string"">5101-17050900672</field>
                                                            <field name=""qty"" type=""numeric"">396.000000</field>
                                                            <field name=""dpm_lot_no"" type=""string""/>
                                                            <field name=""workstation_no"" type=""string"">106</field>
                                                            <field name=""so_no"" type=""string"">GA-1705022-1-1</field>
                                                            <field name=""plan_start_date"" type=""date"">19000101000000000</field>
                                                            <field name=""plan_finish_date"" type=""date"">19000101000000000</field>
                                                        </row>
                                                    </data>
                                                </parameter>
                                            </datainfo>
                                        </data_request>
                                    </param>
                                </payload>
                            </request>";

            var doc = new XmlDocument();
            doc.LoadXml(xmlStr);

            var rowNoteList = doc.SelectNodes("/request/payload/param/data_request/datainfo/parameter/data/row");


            if (rowNoteList != null)
            {
                foreach (XmlNode rowNode in rowNoteList)
                {
                    var fieldNodeList = rowNode.ChildNodes;
                    foreach (XmlNode courseNode in fieldNodeList)
                    {
                        if (courseNode.Attributes != null)
                        {
                            Console.Write(courseNode.Attributes["name"].Value);
                            Console.Write("\t");
                            Console.Write(courseNode.Attributes["type"].Value);
                        }
                        Console.Write("\t");
                        Console.WriteLine(courseNode.InnerText.Trim());
                    }
                    Console.Write("\n");
                }
            }

            Console.Write("\r\nPress any key to continue....");
            Console.Read();

        }
    }
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#将MSMQ消息转换成Json格式【优化】发布时间:2022-07-10
下一篇:
RegularExpressioninC#发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap