c# - How to remove elements from a document? -


is there way iterate through document , remove <:p /> elements if don't have runs? trying remove paragraphs if this:

<w:p>     <w:ppr>         <w:pstyle w:val="heading1" />         <w:numpr>             <w:ilvl w:val="0" />             <w:numid w:val="0" />         </w:numpr>         <w:ind w:left="432" />     </w:ppr> </w:p> 

here have far, removes empty <w:p /> elements.

foreach (paragraph p in d.descendants<paragraph>().where(x => !x.haschildren).tolist() 

you can call :

foreach (paragraph p in d.descendants<paragraph>()          .where(o=>o.descendants<run>().count() ==0).tolist() 

but keep in mind if have sections in document, may causes problems (check more information : http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.sectionproperties(v=office.14).aspx)


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -