You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue sketches a design to enable easier construction of complex xpath expressions from simple ones without needing to fall back to knowing the full xpath.
The current workflow for this is
#Get the simple xpath from the schema dictionarysimple=schema_dict.tag_xpath(tag_name)
#Build your complex xpath manually with string manipulation
...
#Evaluating the complex xpath
This is used in the xml_settersset_species for example to select specific species
This building of the complex xpath could be designed in a more concise way. This is just a sketch how the usage of this functionality could look. What I have in mind is only adding so called predicates and not wildcard expressions or entering relative expressions https://www.w3schools.com/xml/xpath_syntax.asp
lo_path=schema_dict.tag_xpath('lo', contains='species')
builder=XPathBuilder(lo_path, filters={
'species': {'index': {'<=': 3 }}, #Get the first three species nodes'lo': {'type': {'==': 'SCLO'}}
})
xpath=builder.build() #/fleurInput/atomSpecies/species[position()<=3]/lo[@type='SCLO']
The syntax of the filters dictionary is borrowed from the AiiDA Querybuilder. I don't know if this is the best approach but it seems like a robust starting point to me.
Ultimately this allows to add an argument filters or where to specify these filters for xml_setters/xml_getters
More things that can be added on to this are:
Subclassing the basic XPathBuilder with SchemaXPathBuilder with additional validation and functionality from teh schema dictionaries
Instead of the example /fleurInput/atomSpecies/species[position()<=3]/lo[@type='SCLO'] the recommended safe way to do these variable expressions is /fleurInput/atomSpecies/species[position()<=$index]/lo[@type=$type] and passing the actual values as variables to the Xpath engine. This can also be supported by this builder mechanism
The text was updated successfully, but these errors were encountered:
This issue sketches a design to enable easier construction of complex xpath expressions from simple ones without needing to fall back to knowing the full xpath.
The current workflow for this is
This is used in the
xml_setters
set_species
for example to select specific speciesThis building of the complex xpath could be designed in a more concise way. This is just a sketch how the usage of this functionality could look. What I have in mind is only adding so called predicates and not wildcard expressions or entering relative expressions https://www.w3schools.com/xml/xpath_syntax.asp
The syntax of the filters dictionary is borrowed from the AiiDA Querybuilder. I don't know if this is the best approach but it seems like a robust starting point to me.
Ultimately this allows to add an argument
filters
orwhere
to specify these filters forxml_setters
/xml_getters
More things that can be added on to this are:
XPathBuilder
withSchemaXPathBuilder
with additional validation and functionality from teh schema dictionaries/fleurInput/atomSpecies/species[position()<=3]/lo[@type='SCLO']
the recommended safe way to do these variable expressions is/fleurInput/atomSpecies/species[position()<=$index]/lo[@type=$type]
and passing the actual values as variables to the Xpath engine. This can also be supported by this builder mechanismThe text was updated successfully, but these errors were encountered: