morexyoung 2020-04-26
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));