C# XDocument的使用
来源:互联网 发布:快速排序算法的例子 编辑:程序博客网 时间:2024/06/07 20:48
XDocument保存XML文件
XDocument document = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); XElement header = new XElement("SFIS-ISN", new XElement("MSGTYPE", mAsusReportHeader.MsgType), new XElement("MSGDATE", mAsusReportHeader.MsgDate), new XElement("MSGID", mAsusReportHeader.MsgId), new XElement("SENDID", mAsusReportHeader.SendId), new XElement("RECEID", mAsusReportHeader.ReceId) );int nStep = 0;//此处数据为集合,可自行添加数据源 foreach (AsusReportMasterEntity mAsusReportMaster in listAsusReportMaster) { nStep++; XElement master = new XElement("MASTER"); master.Add(new XElement("DOCID", mAsusReportMaster.DocId), new XElement("DOCDATETIME", mAsusReportMaster.DocDatetime), new XElement("VENDOR_TYPE", mAsusReportMaster.VendorType), new XElement("VENDOR_ID", mAsusReportMaster.VendorId), new XElement("BU", mAsusReportMaster.Bu), new XElement("HUB_TYPE", mAsusReportMaster.HubType), new XElement("ISN", mAsusReportMaster.Isn), new XElement("ORI_ISN", mAsusReportMaster.OriIsn), new XElement("SSN", mAsusReportMaster.Ssn), new XElement("ASUS_PN", mAsusReportMaster.AsusPn), new XElement("SO_NO", mAsusReportMaster.SoNo), new XElement("SO_LINE", mAsusReportMaster.SoLine), new XElement("DN_NO", mAsusReportMaster.DnNo), new XElement("DN_LINE", mAsusReportMaster.DnLine), new XElement("PO_NO", mAsusReportMaster.PoNo), new XElement("PO_LINE", mAsusReportMaster.PoLine), new XElement("ORDER_QTY", mAsusReportMaster.OrderQty), new XElement("SHIP_QTY", mAsusReportMaster.ShipQty), new XElement("SHIP_DATE", mAsusReportMaster.ShipDate), new XElement("PALLET_ID", mAsusReportMaster.PalletId), new XElement("PALLET_NO", mAsusReportMaster.PalletNo), new XElement("PALLET_NW", mAsusReportMaster.PalletNw == 0 ? (object)null : mAsusReportMaster.PalletNw), new XElement("PALLET_GW", mAsusReportMaster.PalletGw == 0 ? (object)null : mAsusReportMaster.PalletGw), new XElement("CARTON_ID", mAsusReportMaster.CartonId), new XElement("CARTON_NW", mAsusReportMaster.CartonNw), new XElement("CARTON_GW", mAsusReportMaster.CartonGw), new XElement("BOX_QTY", mAsusReportMaster.BoxQty), new XElement("WARRANTY", mAsusReportMaster.Warranty), new XElement("WARR_EXP_DATE", mAsusReportMaster.WarrExpDate), new XElement("DOA", mAsusReportMaster.Doa) ); header.Add(master);}<pre name="code" class="csharp">document.Add(header);//保存文档document.Save(sFileName);
生成后的格式如下:
<?xml version="1.0" encoding="utf-8" standalone="yes"?><SFIS-ISN> <MSGTYPE>SFIS-ISN</MSGTYPE> <MSGDATE>20160823212607</MSGDATE> <MSGID></MSGID> <SENDID>S09A0093</SENDID> <RECEID>ASUS</RECEID> <MASTER> <DOCID></DOCID> <DOCDATETIME>20160823212607</DOCDATETIME> <VENDOR_TYPE>EMS</VENDOR_TYPE> <VENDOR_ID>S09A0093</VENDOR_ID> <BU>ZenFone</BU> <HUB_TYPE></HUB_TYPE> <ISN>E281C672638004</ISN> <ORI_ISN>E281C672638004</ORI_ISN> <SSN>G8AXGY02H886K7L</SSN> <ASUS_PN>90AX0085-M00810</ASUS_PN> <SO_NO></SO_NO> <SO_LINE></SO_LINE> <DN_NO>15160400869</DN_NO> <DN_LINE>12957997</DN_LINE> <PO_NO></PO_NO> <PO_LINE></PO_LINE> <ORDER_QTY>180</ORDER_QTY> <SHIP_QTY>180</SHIP_QTY> <SHIP_DATE>20160823</SHIP_DATE> <PALLET_ID>DG800000189</PALLET_ID> <PALLET_NO>189</PALLET_NO> <PALLET_NW>73.05</PALLET_NW> <PALLET_GW>92</PALLET_GW> <CARTON_ID>CE281F1608110026</CARTON_ID> <CARTON_NW>3.77</CARTON_NW> <CARTON_GW>4.06</CARTON_GW> <BOX_QTY>10</BOX_QTY> <WARRANTY></WARRANTY> <WARR_EXP_DATE></WARR_EXP_DATE> <DOA>N</DOA> </MASTER></SFIS-ISN>
0 0
- C# XDocument的使用
- Linq To Xml 备忘录1(XDocument, XElement的使用)
- XDocument
- C# XDocument.Parse 保留空格space
- asp.net中,使用XDocument操作XML
- 从XmlDocument到XDocument的转换
- C# XML技术总结之XDocument 和XmlDocument
- 关于DataGridView,ComboBox,XDocument和XElement的一点总结
- Linq中的XDocument怎样解析这样的XML?
- XML(4)XDocument和XmlDocument搜索指定的节点
- XDocument类
- Xdocument---Xpath
- XDocument 获取包括第一行的声明(版本、编码)的所有节点
- XDocument 与XElement 区别
- XmlDocument转换为XDocument
- XDocument简单入门
- XmlDocument,XDocument相互转换
- XDocument简单入门
- 线程消息处理机制
- 译文: Manila Admin Reference (Mitaka版本)
- Docker与容器安全
- awk & sed之奇数行与偶数行的打印
- 自定义viewpager的切换速度
- C# XDocument的使用
- (11)HTML5-鼠标单击事件监听
- 简单介绍树回归的算法原理
- 函数式编程
- 记录
- 快速排序C++实现(递归,非递归)
- React Native环境搭建
- Spring中定时任务Quartz集群配置学习
- mongodb 增删改查简单封装