Monday, 19 August 2013

regular expression to find special character & between xml tags

regular expression to find special character & between xml tags

A xml string generated from another model will pass to me, it may contains
some special character such as & in the text of the xml tag.
e.g.
<entry>
<key>state</key>
<value xsi:type="xs:string">ADDDRESS 3 **&** ADDR 4, 12345, HONG
KONG</value>
</entry>
when I build the xml from string will have invalid character error, So I
need to escape the special character &.
I want to use regex to find the & between <value></value> tag and replace
with the &amp;
I have tried some but fail on the regex.
Can anyone give me the some clue on the regex?
besides I use Java 1.6

No comments:

Post a Comment