码迷,mamicode.com
首页 > 其他好文 > 详细

xml格式封装数据

时间:2020-04-26 18:35:40      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:封装数据   convert   load   tostring   doc   Owner   封装   serial   version   

 xml层级关系
XDocument obj = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); //构造根节点 obj.Add(new XElement("request", new XElement("criteriaList", new XElement("criteria", new XElement("warehouseCode", warehousecode), new XElement("ownerCode", whse), new XElement("itemCode", sku.sku), new XElement("itemId", "")))));

XmlDocument doc = new XmlDocument();
doc.LoadXml(obj.ToString());

 var obj = new JObject
                    {
                        {"?xml",new JObject
                            {
                                {"@version","1.0" },
                                {"@encoding","utf-8"}
                            }
                        },
                        { "request", new JObject
                            {
                                {"actionType","add"},
                                {"warehouseCode", warehousecode},
                                {"ownerCode",  whse},
                                {"supplierCode", ""},
                                {"supplierName", "" },
                                { "item", j },
                                {"extendProps", new JObject
                                    {
                                        {"key1", "" },
                                        {"key2", "" },
                                        {"key3", "" },
                                        {"key4", "" },
                                        {"key5", "" }
                                    }
                                }
                            }
                        }
                    };
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(JsonConvert.SerializeObject(obj));

 

xml格式封装数据

标签:封装数据   convert   load   tostring   doc   Owner   封装   serial   version   

原文地址:https://www.cnblogs.com/ZkbFighting/p/12781311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!