zoukankan      html  css  js  c++  java
  • 生成XML、讀取XML

    生成XML方法:

     XmlDocument xml = new XmlDocument();
                               
                    //插入聲明
                    XmlDeclaration xmlDelaration = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
                    XmlElement root = xml.DocumentElement;
                    xml.InsertBefore(xmlDelaration, root);

                    XmlElement node_Results = xml.CreateElement("Results");
                    xml.AppendChild(node_Results);

     return xml.InnerXml;

    或者:

      XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Results></Results>");

     XmlNodeList nodeList = xmldoc.GetElementsByTagName("Results");
                        XmlNode node_results = null;
                        if (nodeList.Count > 0)
                        {
                            node_results = nodeList[0];
                        }

    //屬於Attributes添加方法:

    XmlAttribute _ShipLotNo = xml.CreateAttribute("ShipLotNo");
    _ShipLotNo.Value = lot.Info.ssl_iShipLotNo.ToString();
    node_OrderItem.Attributes.Append(_ShipLotNo);

     return xmldoc.InnerXml;

    **************************************************************************

    讀取XML方法:

     private PrePlanReturnData DeserializePrePlanXML(string strXML)
            {
                PrePlanReturnData rtn = new PrePlanReturnData();
                rtn.PEIs = new List<PrePlanReplyPEI>();
                rtn.ShipLots = new List<PrePlanReplyShipLot>();

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(strXML);
                XmlNodeList list = xml.GetElementsByTagName("RETURNINFO");
                if (list != null)
                {
                    foreach (XmlNode node in list)
                    {
                        rtn.ReturnCode = node["RETURNCODE"].InnerText;
                        rtn.ReturnMessagess = node["RETURNMESSAGE"].InnerText;


                        break;
                    }
                }

                list = xml.GetElementsByTagName("RESULTS");
                if (list != null)
                {
                    foreach (XmlNode node in list)
                    {
                        if (node.Attributes["ProjectNo"] != null)
                        {
                            rtn.OrderNo = node.Attributes["ProjectNo"].Value;
                        }
                        if (node.Attributes["ProjectID"] != null)
                        {
                            rtn.OrderID = Convert.ToInt32(node.Attributes["ProjectID"].Value);
                        }

                        if (rtn.OrderNo == "")
                        {
                            if (node.Attributes["SONo"] != null)
                            {
                                rtn.OrderNo = node.Attributes["SONo"].Value;
                            }
                            if (node.Attributes["SOID"] != null)
                            {
                                rtn.OrderID = Convert.ToInt32(node.Attributes["SOID"].Value);
                            }
                        }

                        if (node["ERRORMESSAGE"] != null)
                        {
                            rtn.ReturnMessagess += "\n" + node["ERRORMESSAGE"].InnerText;
                        }

                        if (node["SUGGESTMESSAGE"] != null)
                        {
                            rtn.ReturnMessagess += "\n" + node["SUGGESTMESSAGE"].InnerText;
                        }
                    }
                }

                list = xml.GetElementsByTagName("ShipLot");
                if (list != null)
                {
                    foreach (XmlNode node in list)
                    {
                        PrePlanReplyShipLot shiplot = new PrePlanReplyShipLot();
                        if (node.Attributes["ShipLotNo"] != null)
                        {
                            shiplot.ShipLotID = Convert.ToInt32(node.Attributes["ShipLotNo"].Value);
                        }

                        if (node["SugBeginDate"] != null)
                        {
                            shiplot.SugBeginDate = StringToDateTime(node["SugBeginDate"].InnerText);
                        }
                        if (node["SugFinishDate"] != null)
                        {
                            shiplot.SugFinishDate = StringToDateTime(node["SugFinishDate"].InnerText);
                        }
                        if (node["SUGGESTMESSAGE"] != null)
                        {
                            shiplot.Message = node["SUGGESTMESSAGE"].InnerText;
                        }
                        if (node["ERRORMESSAGE"] != null)
                        {
                            shiplot.Message = node["ERRORMESSAGE"].InnerText;
                        }

                        rtn.ShipLots.Add(shiplot);
                    }
                }

                list = xml.GetElementsByTagName("PEI");
                if (list != null)
                {
                    foreach (XmlNode node in list)
                    {
                        PrePlanReplyPEI pei = new PrePlanReplyPEI();
                        if (node.Attributes["ProductID"] != null)
                        {
                            pei.ProductID = node.Attributes["ProductID"].Value;
                        }
                        if (node.Attributes["EditionCD"] != null)
                        {
                            pei.EditionCD = node.Attributes["EditionCD"].Value;
                        }
                        if (node.Attributes["ImprintCD"] != null)
                        {
                            pei.ImprintCD = node.Attributes["ImprintCD"].Value;
                        }


                        if (node["CPMInDate"] != null)
                        {
                            pei.CPMInDate = StringToDateTime(node["CPMInDate"].InnerText);
                        }

                        rtn.PEIs.Add(pei);
                    }
                }

                return rtn;
            }

  • 相关阅读:
    About DEBUG_NEW
    [bbk5161] 第107集 第13章 表空间管理 05
    [bbk4975] 第103集 第13章 表空间管理 01
    [bbk5156] 第106集 第13章 表空间管理 04
    [bbk4998] 第104集 第13章 表空间管理 02
    [bbk4965] 第102集 第13章 表空间管理 00
    [bbk5119] 第105集 第13章 表空间管理 03
    如何查看表占用空间情况?
    如何手工回收段空间?
    [bbk5162] 第108集 第13章 表空间管理 06
  • 原文地址:https://www.cnblogs.com/guyuehuanhuan/p/1934224.html
Copyright © 2011-2022 走看看