XmlDocument 类
表示 XML 文档。 可使用此类在文档中加载、验证、编辑、添加和放置 XML。
System.Xml.XmlDocument
用法:
![]() | 从指定的 URL 加载 XML 文档。 | |
![]() | 从指定的 加载 XML 文档。 |
例子:
System.Xml.XmlDocument doc = new System.Xml.Xmldocument(); doc.Load(文件路径) 参考https://www.cnblogs.com/bsdbqling/p/9167886.html
用法:
![]() | 选择第一个 XmlNode ,与 XPath 表达式匹配。(继承自 。) |
XmlNode nd = doc.SelectSingleNode("Models/Model[@id='"+infoType+"']");
用法:
程序集: System.Xml(位于 System.Xml.dll)
public virtual XmlAttributeCollection Attributes { get; }
属性值
Type:XmlAttributeCollection 包含节点的属性。
如果节点为 XmlNodeType.Element 类型,则返回该节点的属性。 否则,此属性将返回 null。
例子:
nd.Attributes["exttable"].value;
nd.Attributes["filed"].value;
附加文件如下:
string tempFileName = AppDomain.CurrentDomain.BaseDirectory + "temp\\" + Guid.NewGuid().ToString() + ".docx";string modelPath = AppDomain.CurrentDomain.BaseDirectory + "Model\\WordModel\\InfoImpModel.docx";string configFile = AppDomain.CurrentDomain.BaseDirectory + "Configure\\Bizz\\ExpConfig.xml";System.Xml.XmlDocument doc = new System.Xml.XmlDocument();doc.Load(configFile);XmlNode nd = doc.SelectSingleNode("Models/Model[@id='" + infoType + "']");XmlNode mbnd = doc.SelectSingleNode("Models/Model[@id='" + infoType + "']/BookMark[@name='详细内容']");string extTable = nd.Attributes["exttable"].Value;string contentField = mbnd.Attributes["filed"].Value;