dave-howard / vsdx

vsdx - A python library for processing .vsdx files
BSD 3-Clause "New" or "Revised" License
67 stars 25 forks source link

Data Properties not complete #55

Closed Kranfield closed 11 months ago

Kranfield commented 1 year ago

Hello Dave,

I noticed that the data_properties method does not return everything in the shape properties. I also found why. Sometimes there is no cell.attrib["V"] but there is a cell.text, like this :

<Section N='Property'>
                <Row N='Row_2'>
                    <Cell N='Value' V='Placeholder' U='STR'/>
                    <Cell N='LangID' V='en-IN'/>
                </Row>
                <Row N='Row_3'>
                    <Cell N='Value' V='Placeholder' U='STR'/>
                    <Cell N='LangID' V='en-IN'/>
                </Row>
                <Row N='Row_5'>
                    <Cell N='Value' V='Placeholder' U='STR'/>
                </Row>
                <Row N='Row_6'>
                    <Cell N='Value' U='STR'>Placeholder but not in Value
</Cell>
                    <Cell N='LangID' V='en-IN'/>
                </Row>
            </Section>

This exception is not taken in account in your code :

def __init__(self, *, xml: Element, shape: Shape):
        """Represents a single Data Property item associated with a Shape object"""
        name = xml.attrib.get('N')
        # get Cell element for each property of DataProperty
        label_cell = xml.find(f'{namespace}Cell[@N="Label"]')
        value_cell = xml.find(f'{namespace}Cell[@N="Value"]')
        value = value_cell.attrib.get('V') if type(value_cell) is Element else None

The else should be replaced by (in my opinion) :

elif value_cell.text : 
    value = value_cell.text 
else : 
    value = None

(or maybe something a bit cleaner)

Regards,

Quentin

Kranfield commented 1 year ago

Hello

Here is the correction that I made to the beginning of the DataProperty init method :

def __init__(self, *, xml: Element, shape: Shape):
        """Represents a single Data Property item associated with a Shape object"""
        name = xml.attrib.get('N')
        # get Cell element for each property of DataProperty
        label_cell = xml.find(f'{namespace}Cell[@N="Label"]')
        value_cell = xml.find(f'{namespace}Cell[@N="Value"]')
        value = value_cell.attrib.get('V') if type(value_cell) is Element else None
        if type(value_cell) is Element and value_cell.attrib.get('V') != None:
            value = value_cell.attrib.get('V')
        elif value_cell.text:
            value = value_cell.text
        else:
            value = None

This correction is working fine for me, maybe you can integrate it ?

Regards, Quentin

dave-howard commented 1 year ago

Thanks for you for feedback and proposal - looks good and I have integrated your changes 👍

Cheers Dave