• 2 replies
  • Latest Post - ‏2012-08-18T20:32:03Z by anost
13 Posts

Pinned topic remove (ending) blanks from xml element - rtim

‏2012-08-15T14:36:48Z |
Hi all,

I wonder if there is any xquery built-in function to right trim elements stored in a xml cell?
Here is a short example:

create table customer(id integer, info XML); insert into customer values (123, 
'<customerinfo Cid="1002"> <name>Jim </name> <addr country=
"Canada"> <street>25 EastCreek</street> <city>Markham</city> <prov-state>Ontario</prov-state> <pcode-zip>N9C 3T6</pcode-zip> </addr> <phone type=
"work">905-555-7258</phone> </customerinfo>

Assuming I want to remove the last white-space inside <name>Jim </name>. So far I have:

select XMLQUERY(
' copy $newinfo := $INFO modify 

for $j in $newinfo/customerinfo/name 


do replace value of $j with fn:substring-before(xs:string($j),

return $newinfo
' ) from customer WHERE id = 123;

But its not really satisfying, because its not working if I would have a white-space inside the element, e.g. <name>Jim Noodle </name>.

Thanks for any help,
Updated on 2012-08-18T20:32:03Z at 2012-08-18T20:32:03Z by anost