xmlschema icon indicating copy to clipboard operation
xmlschema copied to clipboard

XMLSchemaConverter, text_key

Open william-allen-harris opened this issue 6 years ago • 2 comments

Hello, Thank you very much for the package. I just have a quick question about the XMLSchemaConverter.

For the XMLSchemaConverter, why is it necessary for the text_key to not be letters or underscores? XMLSchemaConverter(text_key='_')

raise XMLSchemaValueError(msg.format(name, value))] xmlschema.exceptions.XMLSchemaValueError: text_key cannot includes latters or underscores: '_'`

This limits the converted dictionary or JSON to be used with JSON operating packages such as jsonpath_ng. For example, the jsonpath_ng package is unable to parse paths which include symbols in the str path.

Are there any drawbacks from creating my own Converter and overwriting the setattr function to exclude the error check?

william-allen-harris avatar Jun 04 '20 18:06 william-allen-harris

Hi,

it is a precaution for avoiding conflicts between attribute/element names and prefixes. This is especially true for attribute prefix, that can cause problems with each element that have the name starting with the same prefix.

I can try to remove this constraint but also adding checks on proposed prefixes at schema level, when creating the converter instance used for decoding/encoding (raising a ValueError in case a prefix has a conflict with any element/attribute).

Considering this meanwhile you can derive your custom class that remove this check.

Thanks

brunato avatar Jun 05 '20 07:06 brunato

In new release v1.2.1 the text_key, attr_prefix and cdata_prefix can be set also with letters and underscores. I didn't wrote any check at schema level, only refined the prefix checks in converters to avoid collisions with names (anyway collisions could affect the encoding process only, the decoding have no problems).

Cheers

brunato avatar Jun 12 '20 16:06 brunato