Skip to content

AttributeError: 'lxml.etree._Element' object has no attribute 'fldCharType' #28

@koo5

Description

@koo5

all the fldChar tags have a fldCharType in my document.

> grep fldChar -r eee | grep -v fldCharType
(venv) [01:11:24] koom@dev1 /home/koom/docx2knownet [0|1] 

> pushd eee; zip -r ../eee.docx .; popd
updating: docProps/ (stored 0%)
updating: docProps/core.xml (deflated 47%)
updating: docProps/app.xml (deflated 51%)
updating: customXml/ (stored 0%)
updating: customXml/itemProps1.xml (deflated 36%)
updating: customXml/_rels/ (stored 0%)
updating: customXml/_rels/item1.xml.rels (deflated 36%)
updating: customXml/item1.xml (deflated 39%)
updating: [Content_Types].xml (deflated 80%)
updating: _rels/ (stored 0%)
updating: _rels/.rels (deflated 61%)
updating: word/ (stored 0%)
updating: word/header2.xml (deflated 57%)
updating: word/media/ (stored 0%)
updating: word/media/image1.png (stored 0%)
updating: word/media/image2.png (deflated 23%)
updating: word/media/image3.png (deflated 4%)
updating: word/webSettings.xml (deflated 86%)
updating: word/header1.xml (deflated 70%)
updating: word/footnotes.xml (deflated 65%)
updating: word/styles.xml (deflated 90%)
updating: word/document.xml (deflated 94%)
updating: word/theme/ (stored 0%)
updating: word/theme/theme1.xml (deflated 79%)
updating: word/numbering.xml (deflated 95%)
updating: word/endnotes.xml (deflated 64%)
updating: word/fontTable.xml (deflated 80%)
updating: word/settings.xml (deflated 77%)
updating: word/_rels/ (stored 0%)
updating: word/_rels/settings.xml.rels (deflated 36%)
updating: word/_rels/document.xml.rels (deflated 84%)
(venv) [01:11:27] koom@dev1 /home/koom/docx2knownet  

> ./main.py eee.docx
fn: eee.docx
Traceback (most recent call last):
  File "/home/koom/docx2knownet/./main.py", line 52, in <module>
    print(json.dumps(simplify(docx.Document(fn),{"remove-leading-white-space":False}), indent=4))
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/__init__.py", line 33, in simplify
    out = document(doc.element).to_json(doc, _options)
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/base.py", line 106, in to_json
    "VALUE": [ elt.to_json(doc, options) for elt in self],
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/base.py", line 106, in <listcomp>
    "VALUE": [ elt.to_json(doc, options) for elt in self],
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/body.py", line 25, in to_json
    JSON = elt.to_json(doc, options, iter_me)
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/paragraph.py", line 142, in to_json
    out: Dict[str, Any] = super(paragraph, self).to_json(doc, options, super_iter)
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/paragraph.py", line 27, in to_json
    for elt in run_iterator:
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/base.py", line 61, in __iter__
    for elt in xml_iter(node,
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/iterators/generic.py", line 167, in xml_iter
    for elt in xml_iter(current, handlers.TAGS_TO_NEST[current.tag], _msg):
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/iterators/generic.py", line 156, in xml_iter
    yield handlers.TAGS_TO_YIELD[current.tag](current)
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/form.py", line 106, in __init__
    super(fldChar, self).__init__(x)
  File "/home/koom/docx2knownet/venv/lib/python3.10/site-packages/simplify_docx/elements/base.py", line 36, in __init__
    self.props[prop] = getattr(x, prop)
AttributeError: 'lxml.etree._Element' object has no attribute 'fldCharType'

the offender:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:o="urn:schemas-microsoft-com:office:office"
            xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
            xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml"
            xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
            xmlns:w10="urn:schemas-microsoft-com:office:word"
            xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
            xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
    <w:body>
        <w:p w:rsidR="008650CC" w:rsidRPr="00901306" w:rsidRDefault="00B62871" w:rsidP="00901306">
            <w:pPr>
                <w:pStyle w:val="DOCType"/>
            </w:pPr>
            <w:r w:rsidRPr="00901306">
                <w:fldChar w:fldCharType="begin"/>
            </w:r>
            <w:r w:rsidR="006D26CC" w:rsidRPr="00901306">
                <w:instrText xml:space="preserve"> set DOCnumber "</w:instrText>
            </w:r>
            <w:r w:rsidR="00130235" w:rsidRPr="00901306">
                <w:instrText>Dddd.</w:instrText>
            </w:r>
            <w:r w:rsidR="006D26CC" w:rsidRPr="00901306">
                <w:instrText xml:space="preserve">" </w:instrText>
            </w:r>
            <w:r w:rsidRPr="00901306">
                <w:fldChar w:fldCharType="separate"/>
            </w:r>
            <w:bookmarkStart w:id="0" w:name="DOCnumber"/>
            <w:r w:rsidR="00130235" w:rsidRPr="00901306">
                <w:t>Dddd.</w:t>
            </w:r>
            <w:bookmarkEnd w:id="0"/>
            <w:r w:rsidRPr="00901306">
                <w:fldChar w:fldCharType="end"/>
            </w:r>
        </w:p>
    </w:body>
</w:document>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions