Re: The "replaceAll" method of the String Class can't work, if a "?" character is in the value of an attribute of a XMLString!
On Sep 12, 11:35 pm, Lew <l...@lewscanon.com> wrote:
Ed wrote:
The sample code below doesn't work, but if you take out the Question
Mark character, "?" in front of the value "Print" of the "action"
attribute, it does work!
Does anyone here know an other workaround? Thanks in advance!
You need to watch where line breaks go in source posts to Usenet. You got a
stray greater-than character ('>', a.k.a., "right angle bracket") that
belonged with the xml PI, but was somehow moved to a different line.
Come on, dude! Are you so stupid, to not understand that the code
works, and you may need to move the bracket, where it supposes to be,
when running it!
Also, the variable "XMLString", being a variable, should start with a
lower-case letter, by convention.
Where did you get that rule, Mr. Conformist!
Don't lecture to anyone here, your nonsense rule! Try to think out of
the box sometime!
public class Questionmark_TEST{
public Questionmark_TEST(){}
public static void main(String [] args){
String XMLString =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+
"<categories><NodeOne action='Print?'/></categories>";
String OldNode = "<NodeOne action='Print?'/>";
String NewNode = "<NodeOne action='Print?'>empty</NodeOne>";
XMLString = XMLString.replaceAll(OldNode,NewNode);
System.out.println("new XMLString : "+XMLString.toString());
}
}
Did you read the Javadocs on the replaceAll() method?
<http://java.sun.com/javase/6/docs/api/java/lang/String.html#replaceAl...)>
The first argument is a regular expression, in which the question mark has
special significance.
But you never answered my question though! Take a look what Roedy
replied to me! That's kind of an answer, I was looking for!