Indenting XML query result from a function

Tuesday, 16 February 2016 · 5 messages
HE
Hondros, Constantine (ELS-AMS)16 Feb 2016 13:42 #
This is probably easy, but I can't find an inbuilt method or function to do this easily. I have a function that will return certain nodes from a DB. The DB was built with CHOP off - plenty of white-space present between nodes.
declare function dq:errorGivenName($db as xs:string) as element()* {
  db:open(concat($db, '_author))/*/*[matches(givenname, "[^\p{L}\p{M}-[\s-'''\.]]")]
};
I can't predict where the function will be called so I've got no control over serialization parameters. Instead I'd like to pretty print the XML fragment returned by the function. I could write something to do this, but there must be a simple way ... right? C. ________________________________ Elsevier B.V. Registered Office: Radarweg 29, 1043 NX Amsterdam, The Netherlands, Registration No. 33156677, Registered in The Netherlands.
CG
Christian Grün16 Feb 2016 13:59 #
Hi Constantine,
Quoted text · Hondros, Constantine (ELS-AMS) · 2 lines
> db:open(concat($db, '_author))/*/*[matches(givenname, > "[^\p{L}\p{M}-[\s-'’‘\.]]")]
I’m not sure what this is supposed to do? ;) Do you want to find whitespace-only text nodes?
HE
Hondros, Constantine (ELS-AMS)16 Feb 2016 15:54 #
Hi Christian, Oh, this is just a regexp to pull out some odd looking values from a DB containing names. The point of my question is that the function returns a number of XML fragments which I subsequently want to indent properly before passing them on. That's what I can't figure out - beyond rolling my own function.
Quoted text · Christian Grün · 11 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: 16 February 2016 13:59 To: Hondros, Constantine (ELS-AMS) Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Indenting XML query result from a function Hi Constantine, > db:open(concat($db, '_author))/*/*[matches(givenname, > "[^\p{L}\p{M}-[\s-'’‘\.]]")] I’m not sure what this is supposed to do? ;) Do you want to find whitespace-only text nodes? Elsevier B.V. Registered Office: Radarweg 29, 1043 NX Amsterdam, The Netherlands, Registration No. 33156677, Registered in The Netherlands.
CG
Christian Grün16 Feb 2016 16:00 #
For proper indentation, you’ll first have to normalize your XML fragments by e.g. removing all whitespace-only text nodes before calling fn:serialize. Does this help?
Quoted text · Constantine (ELS-AMS) · 25 lines
On Tue, Feb 16, 2016 at 3:54 PM, Hondros, Constantine (ELS-AMS) <C.Hondros at elsevier.com> wrote: > Hi Christian, > > Oh, this is just a regexp to pull out some odd looking values from a DB containing names. The point of my question is that the function returns a number of XML fragments which I subsequently want to indent properly before passing them on. That's what I can't figure out - beyond rolling my own function. > > > > -----Original Message----- > From: Christian Grün [mailto:christian.gruen at gmail.com] > Sent: 16 February 2016 13:59 > To: Hondros, Constantine (ELS-AMS) > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Indenting XML query result from a function > > Hi Constantine, > >> db:open(concat($db, '_author))/*/*[matches(givenname, >> "[^\p{L}\p{M}-[\s-'’‘\.]]")] > > I’m not sure what this is supposed to do? ;) Do you want to find whitespace-only text nodes? > > ________________________________ > > Elsevier B.V. Registered Office: Radarweg 29, 1043 NX Amsterdam, The Netherlands, Registration No. 33156677, Registered in The Netherlands.
HE
Hondros, Constantine (ELS-AMS)16 Feb 2016 16:34 #
D'oh. Of course :)` Thanks.
Quoted text · Christian Grün · 32 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: 16 February 2016 16:00 To: Hondros, Constantine (ELS-AMS) Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Indenting XML query result from a function For proper indentation, you’ll first have to normalize your XML fragments by e.g. removing all whitespace-only text nodes before calling fn:serialize. Does this help? On Tue, Feb 16, 2016 at 3:54 PM, Hondros, Constantine (ELS-AMS) <C.Hondros at elsevier.com> wrote: > Hi Christian, > > Oh, this is just a regexp to pull out some odd looking values from a DB containing names. The point of my question is that the function returns a number of XML fragments which I subsequently want to indent properly before passing them on. That's what I can't figure out - beyond rolling my own function. > > > > -----Original Message----- > From: Christian Grün [mailto:christian.gruen at gmail.com] > Sent: 16 February 2016 13:59 > To: Hondros, Constantine (ELS-AMS) > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Indenting XML query result from a function > > Hi Constantine, > >> db:open(concat($db, '_author))/*/*[matches(givenname, >> "[^\p{L}\p{M}-[\s-'’‘\.]]")] > > I’m not sure what this is supposed to do? ;) Do you want to find whitespace-only text nodes? > > ________________________________ > > Elsevier B.V. Registered Office: Radarweg 29, 1043 NX Amsterdam, The Netherlands, Registration No. 33156677, Registered in The Netherlands. Elsevier B.V. Registered Office: Radarweg 29, 1043 NX Amsterdam, The Netherlands, Registration No. 33156677, Registered in The Netherlands.

⚡Generated with XQuery