【发布时间】:2015-05-05 00:30:44
【问题描述】:
所以我正在尝试检查文档是否具有某些属性。例如,我有一篇硕士论文样本,我必须检查的一件事是标题是否以标题页为中心。到目前为止,我已经创建了 docx 文件的 xmlDocument 对象,因此我可以访问它的 Xml。代码是
public void ProcessDocument(string documentFullPath){
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(documentFullPath, true)){
NameTable table = new NameTable();
XmlNamespaceManager xnm = new XmlNamespaceManager(table);
xnm.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingxml/2006/main");
XmlDocument tempDoc = new XmlDocument();
tempDoc.LoadXml(myDoc.MainDocumentPart.Document.InnerXml);
}
}
我的问题是:访问文档的 xml 并找出文档是否具有我要查找的属性的最有效方法是什么?我是将 xml 转换为字符串并使用正则表达式还是做其他更有效的事情?我的代码在 C# 中。任何帮助将不胜感激。
【问题讨论】:
标签: c# xml openxml openxml-sdk wordprocessingml