XmlHlelper.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. using Abp.Logging;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Xml;
  9. namespace VberZero.Tools.FileHelpers;
  10. public static class XmlHelper
  11. {
  12. /// <summary>
  13. /// XML转换成DataTable
  14. /// </summary>
  15. /// <param name="xmlDS"></param>
  16. /// <returns></returns>
  17. public static string ConvertDataTableToXML(this DataTable xmlDS)
  18. {
  19. XmlTextWriter writer = null;
  20. try
  21. {
  22. var stream = new MemoryStream();
  23. writer = new XmlTextWriter(stream, Encoding.UTF8);
  24. xmlDS.WriteXml(writer);
  25. int count = (int)stream.Length;
  26. byte[] arr = new byte[count];
  27. stream.Seek(0, SeekOrigin.Begin);
  28. stream.Read(arr, 0, count);
  29. UTF8Encoding utf = new UTF8Encoding();
  30. return utf.GetString(arr).Trim();
  31. }
  32. catch (Exception e)
  33. {
  34. LogHelper.LogException(e);
  35. return "";
  36. }
  37. finally
  38. {
  39. writer?.Close();
  40. }
  41. }
  42. /// <summary>
  43. /// XML转换成DataTable
  44. /// </summary>
  45. /// <param name="xmlData"></param>
  46. /// <returns></returns>
  47. public static DataSet ConvertXMLToDataSet(this string xmlData)
  48. {
  49. XmlTextReader reader = null;
  50. try
  51. {
  52. DataSet xmlDS = new DataSet();
  53. var stream = new StringReader(xmlData);
  54. reader = new XmlTextReader(stream);
  55. xmlDS.ReadXml(reader);
  56. return xmlDS;
  57. }
  58. catch (Exception e)
  59. {
  60. LogHelper.LogException(e);
  61. return null;
  62. }
  63. finally
  64. {
  65. reader?.Close();
  66. }
  67. }
  68. }
  69. /// <summary>
  70. /// Object mapping of a xml file
  71. /// </summary>
  72. public class XModel
  73. {
  74. /// <summary>
  75. /// Directory of this xml file
  76. /// </summary>
  77. public string XmlDirectory { get; set; }
  78. /// <summary>
  79. /// Xml file name
  80. /// </summary>
  81. public string FileName { get; set; }
  82. /// <summary>
  83. /// Xml file encode
  84. /// </summary>
  85. public string Encode { get; set; }
  86. /// <summary>
  87. /// Root tag
  88. /// </summary>
  89. public XmlTag Root { get; set; }
  90. /// <summary>
  91. /// XmlDocument object of this xml file
  92. /// </summary>
  93. private XmlDocument XmlDoc { get; set; }
  94. #region constructor
  95. /// <summary>
  96. /// Default constructor
  97. /// </summary>
  98. public XModel()
  99. {
  100. }
  101. /// <summary>
  102. /// Constructor: Create XmlModel from XmlTag and save xml file
  103. /// </summary>
  104. /// <param name="directory">directory</param>
  105. /// <param name="fileName">fileName</param>
  106. /// <param name="encode">encode type</param>
  107. /// <param name="root">root tag</param>
  108. public XModel(string directory, string fileName, string encode, XmlTag root)
  109. {
  110. CreateWithFile(directory, fileName, encode, root);
  111. }
  112. /// <summary>
  113. /// Constructor: Create XmlModel from XmlTag only
  114. /// </summary>
  115. /// <param name="root">root tag</param>
  116. public XModel(XmlTag root)
  117. {
  118. CreateWithOutFile(root);
  119. }
  120. /// <summary>
  121. /// Constructor: Read XmlModel From xml file
  122. /// </summary>
  123. /// <param name="directory">directory</param>
  124. /// <param name="fileName">fileName</param>
  125. public XModel(string directory, string fileName)
  126. {
  127. Read(directory, fileName);
  128. }
  129. /// <summary>
  130. /// Constructor: Read XmlModel From xml string
  131. /// </summary>
  132. /// <param name="xml">xml string</param>
  133. public XModel(string xml)
  134. {
  135. Read(xml);
  136. }
  137. #endregion constructor
  138. #region Create and Read XmlModel
  139. /// <summary>
  140. /// Create XmlModel from XmlTag and save xml file
  141. /// </summary>
  142. /// <param name="directory">directory</param>
  143. /// <param name="fileName">fileName</param>
  144. /// <param name="encode">encode type</param>
  145. /// <param name="root">root tag</param>
  146. public void CreateWithFile(string directory, string fileName, string encode, XmlTag root)
  147. {
  148. XmlDirectory = directory;
  149. FileName = fileName;
  150. Encode = encode;
  151. Root = root;
  152. Save();
  153. }
  154. /// <summary>
  155. /// Create XmlModel from XmlTag only
  156. /// </summary>
  157. /// <param name="root"></param>
  158. public void CreateWithOutFile(XmlTag root)
  159. {
  160. Root = root;
  161. }
  162. /// <summary>
  163. /// Read XmlModel From xml file
  164. /// </summary>
  165. /// <param name="directory">directory</param>
  166. /// <param name="fileName">fileName</param>
  167. public void Read(string directory, string fileName)
  168. {
  169. XmlDirectory = directory;
  170. FileName = fileName;
  171. XmlDoc = new XmlDocument();
  172. XmlDoc.Load(directory + fileName);
  173. Root = NodeToTag(XmlDoc.DocumentElement);
  174. }
  175. /// <summary>
  176. /// Read XmlModel From xml string
  177. /// </summary>
  178. /// <param name="xml">xml string</param>
  179. public void Read(string xml)
  180. {
  181. XmlDoc = new XmlDocument();
  182. XmlDoc.LoadXml(xml);
  183. Root = NodeToTag(XmlDoc.DocumentElement);
  184. }
  185. #endregion Create and Read XmlModel
  186. /// <summary>
  187. /// Get current XmlModel's XmlDocument type object
  188. /// </summary>
  189. /// <returns></returns>
  190. public XmlDocument GetXmlDocument()
  191. {
  192. //create XmlModel xmldoc is null
  193. if (XmlDoc == null)
  194. {
  195. XmlDoc = new XmlDocument();
  196. }
  197. //replace root
  198. if (XmlDoc.DocumentElement != null)
  199. {
  200. XmlDoc.RemoveChild(XmlDoc.DocumentElement);
  201. }
  202. XmlDoc.AppendChild(TagToNode(Root));
  203. //add or edit declaration
  204. if (XmlDoc.FirstChild is XmlDeclaration declaration)
  205. {
  206. if (!string.IsNullOrEmpty(Encode))
  207. {
  208. declaration.Encoding = Encode;
  209. }
  210. }
  211. else
  212. {
  213. if (string.IsNullOrEmpty(Encode))
  214. {
  215. throw new Exception("Encode can't be empty");
  216. }
  217. XmlDoc.InsertBefore(XmlDoc.CreateXmlDeclaration("1.0", Encode, ""), XmlDoc.FirstChild);
  218. }
  219. return XmlDoc;
  220. }
  221. /// <summary>
  222. /// Save Object to file
  223. /// XmlDirectory and FileName and Encode need to be set before save
  224. /// </summary>
  225. public void Save()
  226. {
  227. if (Root == null)
  228. {
  229. throw new Exception("Root can't be null");
  230. }
  231. if (string.IsNullOrEmpty(XmlDirectory) || string.IsNullOrEmpty(FileName))
  232. {
  233. throw new Exception("XmlDirectory and FileName need to be set before save");
  234. }
  235. //generate xmldocument
  236. GetXmlDocument();
  237. if (!Directory.Exists(XmlDirectory))
  238. {
  239. Directory.CreateDirectory(XmlDirectory);
  240. }
  241. XmlDoc.Save(XmlDirectory + FileName);
  242. }
  243. /// <summary>
  244. /// Delete file
  245. /// </summary>
  246. public void Delete()
  247. {
  248. if (File.Exists(XmlDirectory + FileName))
  249. {
  250. File.Delete(XmlDirectory + FileName);
  251. }
  252. }
  253. /// <summary>
  254. /// Get xml string
  255. /// </summary>
  256. /// <returns></returns>
  257. public override string ToString()
  258. {
  259. return GetXmlDocument().OuterXml;
  260. }
  261. #region Helper
  262. /// <summary>
  263. /// Recurtion transfer XmlNode into XmlTag
  264. /// </summary>
  265. /// <param name="node">XmlNode</param>
  266. /// <returns></returns>
  267. public XmlTag NodeToTag(XmlNode node)
  268. {
  269. //不转化注释
  270. for (int i = 0; i < node.ChildNodes.Count; i++)
  271. {
  272. if (node.ChildNodes[i].Name == ("#comment"))
  273. {
  274. node.RemoveChild(node.ChildNodes[i]);
  275. }
  276. }
  277. //判断当前节点类型返回对应类型节点
  278. if (node.ChildNodes.Count > 0 && node.FirstChild.NodeType != XmlNodeType.Text)
  279. {
  280. XmlChildTag childTag = new XmlChildTag(node.Name);
  281. //属性不为空添加属性
  282. if (node.Attributes != null)
  283. {
  284. foreach (XmlAttribute attr in node.Attributes)
  285. {
  286. childTag.Attrs.Add(attr.Name, attr.Value);
  287. }
  288. }
  289. //递归添加子节点
  290. foreach (XmlNode childNode in node.ChildNodes)
  291. {
  292. XmlTag tag = NodeToTag(childNode);
  293. if (tag is XmlChildTag xmlChildTag)//根据子节点类型加入对应列表
  294. {
  295. childTag.ChildTagList.Add(xmlChildTag);
  296. }
  297. else
  298. {
  299. childTag.BaseTagList.Add(tag as XmlBaseTag);
  300. }
  301. }
  302. return childTag;
  303. }
  304. else
  305. {
  306. XmlBaseTag baseTag = new XmlBaseTag(node.Name);
  307. //属性不为空添加属性
  308. if (node.Attributes != null)
  309. {
  310. foreach (XmlAttribute attr in node.Attributes)
  311. {
  312. baseTag.Attrs.Add(attr.Name, attr.Value);
  313. }
  314. }
  315. baseTag.InnerText = node.InnerText;
  316. return baseTag;
  317. }
  318. }
  319. /// <summary>
  320. /// Recurtion transfer XmlTag into XmlNode
  321. /// </summary>
  322. /// <param name="tag">XmlTag</param>
  323. /// <returns></returns>
  324. public XmlNode TagToNode(XmlTag tag)
  325. {
  326. XmlNode node = XmlDoc.CreateElement(tag.Name);
  327. foreach (var attr in tag.Attrs)
  328. {
  329. XmlAttribute xmlAttr = XmlDoc.CreateAttribute(attr.Key);
  330. xmlAttr.Value = attr.Value;
  331. node.Attributes?.Append(xmlAttr);
  332. }
  333. if (tag is XmlChildTag childTag)
  334. {
  335. if (childTag.BaseTagList.Count == 0 && childTag.ChildTagList.Count == 0)
  336. {
  337. throw new Exception("A XmlChildTag " + childTag.Name + "'s BaseTagList and ChildTagList can't both empty,if this tag don't have any child please use XmlBaseTag type");
  338. }
  339. //添加对应的子节点
  340. foreach (XmlBaseTag innerTag in childTag.BaseTagList)
  341. {
  342. node.AppendChild(TagToNode(innerTag));
  343. }
  344. foreach (XmlChildTag innerTag in childTag.ChildTagList)
  345. {
  346. node.AppendChild(TagToNode(innerTag));
  347. }
  348. }
  349. else
  350. {
  351. if (tag is XmlBaseTag baseTag) node.InnerText = baseTag.InnerText;
  352. }
  353. return node;
  354. }
  355. /// <summary>
  356. /// Quickly get a XmlChildTag
  357. /// </summary>
  358. /// <param name="tagNames">tag's name input by order</param>
  359. /// <returns></returns>
  360. public XmlChildTag GetChildTag(params string[] tagNames)
  361. {
  362. if (tagNames[0] != Root.Name)
  363. {
  364. throw new Exception("Root tag doesn't match");
  365. }
  366. if (!(Root is XmlChildTag))
  367. {
  368. throw new Exception("Root " + tagNames[0] + " must be XmlChildTag type");
  369. }
  370. XmlChildTag result = (XmlChildTag)Root;
  371. for (int i = 1; i < tagNames.Length; i++)
  372. {
  373. if (result != null && result.ChildTagList.All(t => t.Name != tagNames[i]))
  374. {
  375. throw new Exception("Can't find XmlChildTag tag " + tagNames[i] + " by the input tag names with this order");
  376. }
  377. result = result?.ChildTagList.FirstOrDefault(t => t.Name == tagNames[i]);
  378. }
  379. return result;
  380. }
  381. /// <summary>
  382. /// Quickly get a XmlBaseTag
  383. /// </summary>
  384. /// <param name="tagNames">按顺序输入的节点名称/tag's name input by order</param>
  385. /// <returns></returns>
  386. public XmlBaseTag GetBaseTag(params string[] tagNames)
  387. {
  388. if (tagNames[0] != Root.Name)
  389. {
  390. throw new Exception("Root tag doesn't match");
  391. }
  392. if (Root is XmlBaseTag tag)
  393. {
  394. if (tagNames.Length == 1)
  395. {
  396. return tag;
  397. }
  398. throw new Exception("Root " + tagNames[0] + " is XmlBaseTag type, don't have any childs");
  399. }
  400. XmlChildTag childTag = Root as XmlChildTag;
  401. for (int i = 1; i < tagNames.Length; i++)
  402. {
  403. if (childTag != null && (childTag.ChildTagList.All(t => t.Name != tagNames[i]) && childTag.BaseTagList.All(t => t.Name != tagNames[i])))
  404. {
  405. throw new Exception("Can't find XmlTag " + tagNames[i] + " by the input tag names with this order");
  406. }
  407. //最后一个节点查找BaseTagList,否则查找ChildTagList
  408. if (i == tagNames.Length - 1)
  409. {
  410. if (childTag != null && childTag.BaseTagList.Any(t => t.Name == tagNames[i]))
  411. {
  412. return childTag.BaseTagList.FirstOrDefault(t => t.Name == tagNames[i]);
  413. }
  414. throw new Exception("Tag:" + tagNames[i] + " must be XmlBaseTag type");
  415. }
  416. //找到对应XmlChildTag节点缩小查找范围
  417. if (childTag != null && childTag.ChildTagList.Any(t => t.Name == tagNames[i]))
  418. {
  419. childTag = childTag.ChildTagList.FirstOrDefault(t => t.Name == tagNames[i]);
  420. }
  421. else
  422. {
  423. throw new Exception("Tag:" + tagNames[i] + " must be XmlChildTag type");
  424. }
  425. }
  426. return null;
  427. }
  428. #endregion Helper
  429. }
  430. /// <summary>
  431. /// XmlTag: A xml tag
  432. /// </summary>
  433. public abstract class XmlTag
  434. {
  435. /// <summary>
  436. /// Name
  437. /// </summary>
  438. public string Name { get; set; }
  439. /// <summary>
  440. /// Attributes
  441. /// </summary>
  442. public Dictionary<string, string> Attrs { get; set; }
  443. }
  444. /// <summary>
  445. /// XmlChildTag: A XmlTag that at least have a XmlChildTag or XmlBaseTag inside
  446. /// </summary>
  447. public class XmlChildTag : XmlTag
  448. {
  449. /// <summary>
  450. /// XmlChildTags of this XmlChildTag
  451. /// </summary>
  452. public List<XmlChildTag> ChildTagList { get; set; }
  453. /// <summary>
  454. /// XmlBaseTags of this XmlChildTag
  455. /// </summary>
  456. public List<XmlBaseTag> BaseTagList { get; set; }
  457. /// <summary>
  458. /// Constructor
  459. /// </summary>
  460. /// <param name="name">Tag's Name</param>
  461. public XmlChildTag(string name)
  462. {
  463. Name = name;
  464. Attrs = new Dictionary<string, string>();
  465. ChildTagList = new List<XmlChildTag>();
  466. BaseTagList = new List<XmlBaseTag>();
  467. }
  468. /// <summary>
  469. /// Get a XmlChildTag from this tag
  470. /// </summary>
  471. /// <param name="tagNames">tag's name input by order</param>
  472. /// <returns></returns>
  473. public XmlChildTag GetChildTag(params string[] tagNames)
  474. {
  475. XmlChildTag result = this;
  476. foreach (var tagName in tagNames)
  477. {
  478. if (result != null && result.ChildTagList.All(t => t.Name != tagName))
  479. {
  480. throw new Exception("Can't find XmlChildTag tag " + tagName + " by the input tag names with this order");
  481. }
  482. result = result?.ChildTagList.FirstOrDefault(t => t.Name == tagName);
  483. }
  484. return result;
  485. }
  486. /// <summary>
  487. /// Get a XmlBaseTag from this tag
  488. /// </summary>
  489. /// <param name="tagNames">tag's name input by order</param>
  490. /// <returns></returns>
  491. public XmlBaseTag GetBaseTag(params string[] tagNames)
  492. {
  493. XmlChildTag childTag = this;
  494. for (int i = 0; i < tagNames.Length; i++)
  495. {
  496. if (childTag != null && (childTag.ChildTagList.All(t => t.Name != tagNames[i]) && childTag.BaseTagList.All(t => t.Name != tagNames[i])))
  497. {
  498. throw new Exception("Can't find XmlTag tag " + tagNames[i] + " by the input tag names with this order");
  499. }
  500. //最后一个节点查找BaseTagList,否则查找ChildTagList
  501. if (i == tagNames.Length - 1)
  502. {
  503. if (childTag != null && childTag.BaseTagList.Any(t => t.Name == tagNames[i]))
  504. {
  505. return childTag.BaseTagList.FirstOrDefault(t => t.Name == tagNames[i]);
  506. }
  507. throw new Exception("Tag:" + tagNames[i] + " must be XmlBaseTag type");
  508. }
  509. //找到对应XmlChildTag节点缩小查找范围
  510. if (childTag != null && childTag.ChildTagList.Any(t => t.Name == tagNames[i]))
  511. {
  512. childTag = childTag.ChildTagList.FirstOrDefault(t => t.Name == tagNames[i]);
  513. }
  514. else
  515. {
  516. throw new Exception("Tag:" + tagNames[i] + " must be XmlChildTag type");
  517. }
  518. }
  519. return null;
  520. }
  521. }
  522. /// <summary>
  523. /// Xml基础标签:基础标签内不能有子标签,可以有内部文字
  524. /// XmlBaseTag:XmlBaseTag don't have child tag, but inner text
  525. /// </summary>
  526. public class XmlBaseTag : XmlTag
  527. {
  528. /// <summary>
  529. /// InnerText
  530. /// </summary>
  531. public string InnerText { get; set; }
  532. /// <summary>
  533. /// Constructor
  534. /// </summary>
  535. /// <param name="name">Tag's Name</param>
  536. public XmlBaseTag(string name)
  537. {
  538. Name = name;
  539. Attrs = new Dictionary<string, string>();
  540. }
  541. }
  542. #region Test
  543. ////Create a xmlfile
  544. //public static void Create()
  545. //{
  546. // XmlChildTag rootTag = new XmlChildTag("Root");
  547. // rootTag.BaseTagList.Add(new XmlBaseTag("BaseTagOne"));
  548. // XModel myXModel = new XModel("D:\\XML\\", "MyXModel.xml", "utf-8", rootTag);
  549. // Console.WriteLine("Create success");
  550. //}
  551. ////Read a xml file
  552. //public static void Read()
  553. //{
  554. // XModel myXml = new XModel("D:\\XML\\", "MyXModel.xml");
  555. // string rootName = myXml.Root.Name;
  556. // string baseTagOneName = (myXml.Root as XmlChildTag).BaseTagList.First().Name;
  557. // Console.WriteLine("Read success");
  558. //}
  559. ////Edit a xml file
  560. //public static void Edit()
  561. //{
  562. // XModel myXml = new XModel("D:\\XML\\", "MyXModel.xml");
  563. // //edit root name and attributes
  564. // XmlChildTag root = myXml.Root as XmlChildTag;
  565. // root.Name = "NewRoot";
  566. // root.Attrs.Add("attr1", "value1");
  567. // //root add a child tag which have three base tag
  568. // XmlChildTag newChild = new XmlChildTag("NewChild");
  569. // newChild.BaseTagList.Add(new XmlBaseTag("BaseTagTwo"));
  570. // XmlBaseTag baseTagThree = new XmlBaseTag("BaseTagThree");
  571. // baseTagThree.Attrs.Add("testa", "testv");
  572. // newChild.BaseTagList.Add(baseTagThree);
  573. // newChild.BaseTagList.Add(new XmlBaseTag("BaseTagFour") { InnerText = "some text" });
  574. // root.ChildTagList.Add(newChild);
  575. // //save to file
  576. // myXml.Save();
  577. // Console.WriteLine("Edit success");
  578. //}
  579. ////Quickly Get and edit
  580. //public static void QuicklyGet()
  581. //{
  582. // XModel myXml = new XModel("D:\\XML\\", "MyXModel.xml");
  583. // //GetChildTag
  584. // XmlChildTag childA = myXml.GetChildTag("NewRoot", "NewChild");
  585. // childA.Attrs.Add("find", "ture");
  586. // //GetBaseTag
  587. // XmlBaseTag baseTagTwo = myXml.GetBaseTag("NewRoot", "NewChild", "BaseTagTwo");
  588. // baseTagTwo.InnerText = "default return first tag be found";
  589. // //quickly get tag from a XmlChildTag
  590. // XmlChildTag childB = myXml.GetChildTag("NewRoot", "NewChild");
  591. // //lambda
  592. // XmlBaseTag target = childB.BaseTagList.Where(b => b.Attrs.Keys.Contains("testa")).First();
  593. // target.InnerText = "quickly get combine with lambda let you read write xml file very quick";
  594. // //continue quickly get
  595. // XmlBaseTag target2 = childB.GetBaseTag("BaseTagTwo");
  596. // target2.InnerText = "quickly get can be use on XmlChildTag too.";
  597. // myXml.Save();
  598. // Console.WriteLine("QuicklyGet success");
  599. //}
  600. ////Delete
  601. //public static void Delete()
  602. //{
  603. // XModel myXml = new XModel("D:\\XML\\", "MyXModel.xml");
  604. // myXml.Delete();
  605. // Console.WriteLine("Delete success");
  606. //}
  607. ////To string
  608. //public static void PrintXModel()
  609. //{
  610. // XModel myXml = new XModel("D:\\XML\\", "MyXModel.xml");
  611. // Console.WriteLine(myXml.ToString());
  612. //}
  613. ////Create from tag only
  614. //public static void CreateWithOutFile()
  615. //{
  616. // XmlChildTag root = new XmlChildTag("root");
  617. // root.BaseTagList.Add(new XmlBaseTag("base") { InnerText = "test" });
  618. // XModel myXml = new XModel(root);
  619. // myXml.XmlDirectory = "d:\\";
  620. // myXml.FileName = "nofile.xml";
  621. // myXml.Encode = "utf-8";
  622. // myXml.Save();
  623. //}
  624. ////Read from xml String
  625. //public static void ReadXmlString()
  626. //{
  627. // XModel newxml = new XModel(new XModel("D:\\XML\\", "MyXModel.xml").ToString());
  628. // newxml.Root.Name = "newroot";
  629. // newxml.XmlDirectory = "d:\\";
  630. // newxml.FileName = "newxml.xml";
  631. // newxml.Encode = "gbk";
  632. // newxml.Save();
  633. //}
  634. #endregion Test