xpath insert unexpected newlines

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

xpath insert unexpected newlines

Voillequin, Jean-Marc

Hello guys,

 

It seems that xpath function add unexpected newlines in the xml elements it returns as array:

 

postgres=> select version();                                                        

                          version                                                   

------------------------------------------------------------                        

 PostgreSQL 10.3, compiled by Visual C++ build 1800, 64-bit                         

(1 row)                                                                             

                                                                                     

                                                                                     

postgres=>  select ((xpath('/*',xml('<root><a/><b/><c/></root>')))[1])::text;       

  xpath                                                                             

---------                                                                           

 <root> +                                                                            

   <a/> +                                                                           

   <b/> +                                                                           

   <c/> +                                                                            

 </root>                                                                            

(1 row)                                                                             

                                                                                     

A workaround is to have at least one element with a value:

                                                                                    

postgres=> select ((xpath('/*',xml('<root><a/><b/><c/>one value</root>')))[1])::text;

               xpath                                                                 

------------------------------------                                                

 <root><a/><b/><c/>one value</root>                                                 

(1 row)                                                                              

 

Best regards.

 

 

-----------------------------------------
Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

This email was sent to you by Moody’s Investors Service EMEA Limited
Registered office address:
One Canada Square
Canary Wharf
London, E14 5FA
Registered in England and Wales No: 8922701
-----------------------------------------