2013-04-09 3 views
1

.docx 파일의 document.xml 파일을 구문 분석하려고합니다. 텍스트를 검색 한 다음 텍스트가있는 노드를 반환하여 상위 노드로 이동하고 새 노드 유형을 삽입 할 수 있습니다. 이것은 내가 지금까지 가지고있는 SelectSingle 노드를 사용하려고 시도했지만 올바른 경로를 얻을 수없는 것입니다 ("경로가/w : body까지 올 바릅니다). 그래서 나는 텍스트와 그런 식으로 그게 가능하면 노드를 가져옵니다.Xml 텍스트 노드 ID 가져 오기

NameTable nt = new NameTable(); 
XmlNamespaceManager nsManager = new XmlNamespaceManager(nt); 
nsManager.AddNamespace("w", wordmlNamespace); 

// Get the document part from the package. 
// Load the XML in the document part into an XmlDocument instance. 
XmlDocument xdoc = new XmlDocument(nt); 
xdoc.Load(wdDoc.MainDocumentPart.GetStream()); 
XmlNode ALL = xdoc.SelectSingleNode("/w:document/w:body/w:p/w:r[w:t='[ALL]']", nsManager); 
if (ALL != null) 
{ 
    XmlElement vanish = xdoc.CreateElement("//w:vanish /"); 
    XmlNode topNode = ALL.ParentNode.ParentNode; 
    XmlNode topParentNode = topNode.ParentNode; 
    topParentNode.InsertBefore(vanish,topParentNode.FirstChild); 

} 

// Save the document XML back to its document part. 
xdoc.Save(wdDoc.MainDocumentPart.GetStream(FileMode.Create, FileAccess.Write)); 

답변

0

당신의 XPath는 읽어야 "//w:t='[ALL]']".

관련 문제