java - regular expression to find special character & between xml tags -


a xml string generated model pass me, may contains special character such & in text of xml tag.
e.g.

<entry>  <key>state</key>  <value xsi:type="xs:string">adddress  3 & addr 4, 12345, hong kong</value> </entry> 

when build xml string have invalid character error, need escape special character &.
want use regex find & between <value></value> tag , replace &amp;
have tried fail on regex.

can give me clue on regex?

besides use java 1.6

you can use lookahead:

replace

&(?!\w*;)(?=[^<]*</value>) 

by

&amp; 

this works specifying 2 lookaheads. first lookahead (?!\w*;) prevents valid html escape sequences being matched. second lookahead (?=[^<]*</value>) specifies </value> tag must follow text (after amount of non-xml-tag content).

try here.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -