LunarMind/XmlTools.cs
(开头部分) 25KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace SHomeWorkshop.LunarMind
{
/// <summary>
/// 为XmlNode添加了几个扩展方法。
/// </summary>
public static class XmlTools
{
/// <summary>
/// [扩展方法]将一串Xml格式的文本转换成XmlNode节点,并插入为此节点的子节点。
///
/// 异常:
/// ArgumentNullException
/// </summary>
/// <param name="xmlNode">调用本方法的Xml节点(本节点将成为新节点的父节点)。</param>
/// <param name="xmlText">需要转换成新子节点的Xml文本(需要符合Xml格式)。</param>
/// <returns>如果成功转换并插入到当前节点尾部,成为当前节点的最后一个子节点,就返回【新子节点】。失败则返回null。</returns>
public static XmlNode AppendXmlAsChild(this XmlNode xmlNode, String xmlText)
{
if (xmlText == null || xmlText.Length <= 0)
throw new ArgumentNullException("XmlNode的AppendXmlAsChild()扩展方法的“xmlText”参数值不能为null或空字符串!");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlText);
XmlNode newNode = xmlNode.OwnerDocument.CreateNode
(doc.FirstChild.NodeType, doc.FirstChild.Name, doc.FirstChild.NamespaceURI);
foreach (XmlAttribute attribute in doc.FirstChild.Attributes)
{
XmlAttribute newAttribute = xmlNode.OwnerDocument.CreateAttribute(attribute.Name);
newAttribute.Value = attribute.Value;
newNode.Attributes.Append(newAttribute);
}
newNode.InnerXml = doc.FirstChild.InnerXml;
xmlNode.AppendChild(newNode);
return newNode;
}
public static XmlElement AppendXmlAsChild(this XmlElement xmlElement, String xmlText)
{
if (xmlText == null || xmlText.Length <= 0)
throw new ArgumentNullException("XmlNode的AppendXmlAsChild()扩展方法的“xmlText”参数值不能为null或空字符串!");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlText);
XmlElement newElement = xmlElement.OwnerDocument.CreateElement(doc.FirstChild.Name, doc.FirstChild.NamespaceURI);
后面还有 645 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。