Unescaping revritten element name
Hi all, After parsing strings in XML with direct representation (e.g. with CSV and JSON module parsing) the specific entries are represented via elements and their names are rewritten. In particular (as per documentation): "underscores are rewritten to two underscores (__), and characters that are not valid in element names are rewritten to an underscore and the character’s four-digit Unicode.”
It is possible to convert back the element’s node name with an XQuery function present in some module?
Regards,
Mauro
Hi Mauro,
It turns out we’ve thought about adding such a function (and another reverse one) to our modules just recently. We’re still wondering how to name the functions, though; suggestions are welcome!
The attached script contains implementations of the conversions in XQuery; I hope they are helpful.
All the best, Christian
Quoted text · Mauro Mugnaini · 7 lines
> After parsing strings in XML with direct representation (e.g. with CSV and JSON module parsing) the specific entries are represented via elements and their names are rewritten. In particular (as per documentation): "underscores are rewritten to two underscores (__), and characters that are not valid in element names are rewritten to an underscore and the character’s four-digit Unicode.” > > It is possible to convert back the element’s node name with an XQuery function present in some module? > > Regards, > > Mauro
…and a fixed version attached. Thank you to Hans-Jürgen Rennau for pointing me to a bug in my code.
Quoted text · Christian Grün · 24 lines
On Fri, Apr 10, 2020 at 7:51 PM Christian Grün <christian.gruen at gmail.com> wrote: > > Hi Mauro, > > It turns out we’ve thought about adding such a function (and another > reverse one) to our modules just recently. We’re still wondering how > to name the functions, though; suggestions are welcome! > > The attached script contains implementations of the conversions in > XQuery; I hope they are helpful. > > All the best, > Christian > > > > > After parsing strings in XML with direct representation (e.g. with CSV and JSON module parsing) the specific entries are represented via elements and their names are rewritten. In particular (as per documentation): "underscores are rewritten to two underscores (__), and characters that are not valid in element names are rewritten to an underscore and the character’s four-digit Unicode.” > > > > It is possible to convert back the element’s node name with an XQuery function present in some module? > > > > Regards, > > > > Mauro
Written for BaseX 9.3. BaseX may have changed since: please check the current documentation.