timberlandoutlet4smz
New Member
I'm trying to parse through the document.xml file of a .docx file. I would like to search for Text and then return the node that text is located so I can then move up to the parent node and insert a new node type. This is what I have so far, I have been trying to use SelectSingle node but i can't seem to get the path right("the path is correct up until /w:body). So I would like to just search for the text and get the node that way if thats possible.\[code\]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/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));\[/code\]