From 979065689f7e8679a0b23a19b0155deec87cb094 Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <f.spreckelsen@indiscale.com> Date: Mon, 26 Aug 2024 13:15:38 +0200 Subject: [PATCH] DOC: Fix docstring formatting --- src/caoscrawler/__init__.py | 2 +- src/caoscrawler/xml_converter.py | 42 ++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/caoscrawler/__init__.py b/src/caoscrawler/__init__.py index 41b96323..27bdbfd3 100644 --- a/src/caoscrawler/__init__.py +++ b/src/caoscrawler/__init__.py @@ -1,4 +1,4 @@ -from . import converters, utils +from . import converters, utils, xml_converter try: from .conv_impl.spss import SPSSConverter except ImportError as err: diff --git a/src/caoscrawler/xml_converter.py b/src/caoscrawler/xml_converter.py index 5eb9673a..4c724255 100644 --- a/src/caoscrawler/xml_converter.py +++ b/src/caoscrawler/xml_converter.py @@ -48,9 +48,10 @@ from .converters import SimpleFileConverter, ConverterValidationError, Converter class XMLFileConverter(SimpleFileConverter): - """ - Convert XML files. See https://gitlab.indiscale.com/caosdb/src/caosdb-crawler/-/issues/145 + """Convert XML files. See + https://gitlab.indiscale.com/caosdb/src/caosdb-crawler/-/issues/145 for the current suggestion for the specification. + """ def create_children(self, generalStore: GeneralStore, element: StructureElement): @@ -72,33 +73,38 @@ class XMLFileConverter(SimpleFileConverter): class XMLTagConverter(Converter): def create_children(self, generalStore: GeneralStore, element: StructureElement): - """ - Children that are generated by this function are the result of the xpath query given in - the yaml property "xpath". Its default (when not given) is "child::*", so the direct children - of the current xml node. - The xpath expression must be designed in a way that it returns xml tags (and no attributes or texts). - That means, that the axis "attribute::" and the function "text()" must not be used. + """Children that are generated by this function are the + result of the xpath query given in the yaml property + ``xpath``. Its default (when not given) is ``child::*``, so the + direct children of the current xml node. The xpath expression + must be designed in a way that it returns xml tags (and no + attributes or texts). That means, that the axis ``attribute::`` + and the function ``text()`` must not be used. + + The following yaml properties can be used to generate other + types of nodes (text nodes and attribute nodes) as subtree + structure elements: - The following yaml properties can be used to generate other types of nodes (text nodes and attribute nodes) - as subtree structure elements: + :: - # _*_ marks the default: - attribs_as_children: true # true / _false_ - text_as_children: true # true / _false_ - tags_as_children: true # _true_ / false + # _*_ marks the default: + attribs_as_children: true # true / _false_ + text_as_children: true # true / _false_ + tags_as_children: true # _true_ / false The default is to generate the tags matched by the xpath expression only. + - When text_as_children is set to true, text nodes will be generated that contain the text contained in the matched tags. - When attribs_as_children is set to true, attribute nodes will be generated from the attributes of the matched tags. - Namespaces - ---------- + Notes + ----- The default is to take the namespace map from the current node and use it in xpath queries. Because default namespaces cannot be handled by xpath, it is possible to remap the default namespace - using the key "default_namespace". - The key "nsmap" can be used to define additional nsmap entries. + using the key ``default_namespace``. + The key ``nsmap`` can be used to define additional nsmap entries. """ if not isinstance(element, XMLTagElement): -- GitLab