java - Find a xml element with Regex and replace its value -
i understand should not use regex update xml. per requirement have find element based on regex , replace value.
i recording http requests in dispatcher servlet , saving intoa file. while replaying may need upadte 1 of xml.
don't want convert particular xml document
, parse , update convert string. that's why want edit xml in string format.
element name , new value input.
public void findandreplace(string xml, string elementname, string newvalue) { string regex = '/<'+elementname+'></'+elementname+'>'; string updatedelement = '/<'+elementname+'>'+newvalue+'</'+elementname+'>' string updatedxml = xml.replacefirst(regex, updatedelement); }
you don't have create document
in order change xml docuemnt. can quite set streaming xml parser in quite efficient manner. have @ javax.xml.stream
package.
Comments
Post a Comment