pdx:removeChapter

Removes a whole chapter from a Word document.

Description

Element definition

x
 
1
<pdx:utilities>
2
    <pdx:removeChapter pdx:src="" pdx:target="" pdx:searchTerm="" />
3
</pdx:utilities>
4

This element allows to remove (sub)chapters which corresponding heading contains a certain string of text.

This element finds all headings with the required string of text and removes all contents until one hits a new heading of the same or lower level.

Attributes and sub-elements

src

The path to the source Word document.

target

The path to the resulting Word document.

searchTerm

The string of text that we want to search in the headings.

Code samples
#Example 1

config.xml

7
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:config>
4
        <pdx:output pdx:name="output" pdx:type="docx" />
5
    </pdx:config>
6
</pdx:document>
7

content.xml

7
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:utilities>
4
        <pdx:removeChapter pdx:source="/var/www/xmldocx/samples/files/headings.docx" pdx:target="/var/www/xmldocx/samples/DocxUtilities/removeChapter/output_removeChapter.docx" pdx:searchTerm="First Heading" />
5
    </pdx:utilities>
6
</pdx:document>
7

settings.xml

6
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:settings>
4
    </pdx:settings>
5
</pdx:document>
6
10
 
1
import os as os
2
import sys as sys
3
sys.path.append(os.path.abspath("wrappers/python/XmlDocx"))
4
import XmlDocx as XmlDocx
5
document = XmlDocx.XmlDocx("config.xml")
6
document.setDocumentProperties("settings.xml")
7
document.addContent("content.xml")
8
document.setXmlDocxPath("xmldocx path")
9
document.render()
10

The resulting Word document looks like: