By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

The "replaceAll" method of the String Class can't work, if a "?" character is in the value of an attribute of a XMLString!

P: n/a
Ed
Hi All,

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!
////////////////////////////////////////////////////////////Sample
code ////////////////////////////////////////////////////////
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());

}

}
//////////////////////////////////////////Sample
code ///////////////////////////////////////////////////////////////////////////////////////////////

Sep 13 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Ed


Hi All,

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!

///////////Sample code //////////////////

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());

}
}

///////Sample code /////////////////

Sep 13 '07 #2

P: n/a
Lew
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.

Also, the variable "XMLString", being a variable, should start with a
lower-case letter, by convention.
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#replaceAll(java.lang.String,%20java.la ng.String)>

The first argument is a regular expression, in which the question mark has
special significance.

--
Lew
Sep 13 '07 #3

P: n/a
Ed
On Sep 12, 11:35 pm, Lew <l...@lewscanon.comwrote:
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!
Sep 13 '07 #4

P: n/a
On Sep 13, 3:27 pm, Ed <aru...@yahoo.comwrote:
On Sep 12, 11:35 pm, Lew <l...@lewscanon.comwrote:
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!
Tsk.

Lew's reply contain the same information as Roedy's post. To be fair,
Lew's reply contains *more* information than Roedy's. Lew notified
you, politely, about the use of regular expression in
String.replaceAll(), netiquette of using usenet, and globally accepted
Java coding convention, while Roedy simply pointed you to what you
need without much explanation (nothing wrong with Roedy's answer...
but you won't really learn why unless you act by going to his site and
read).

And you chose to thank Roedy and spit in Lew's face.

Sep 13 '07 #5

P: n/a
Quick reminder to all: This is a good time to review
http://catb.org/~esr/faqs/smart-questions.html
.... and to remember that when someone's getting excessively angry,
arguing with them is generally not going to improve matters.

(Killing the thread.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Sep 13 '07 #6

P: n/a
Ed wrote:
On Sep 12, 11:35 pm, Lew <l...@lewscanon.comwrote:
>Also, the variable "XMLString", being a variable, should start with a
lower-case letter, by convention.

Where did you get that rule, Mr. Conformist!
From Sun's Java Coding Convention, which you should study.

Arne
Sep 14 '07 #7

P: n/a
Ed wrote:
On Sep 13, 2:08 am, kcwong <evilwar...@gmail.comwrote:
>To be fair,
Lew's reply contains *more* information than Roedy's.

I don't need more info! If I need more info, I could have spent hours
surfing the internet, and reading all about the String class and the
XML specification.
I am not a Student and don't have a time, I am a Programmer, and
wanted to resolve my current task!
Why ?

If you are not able to lookup some methods in the Java API docs
quicker than posting to usenet, then there are no point in
writing any code - the result should go directly to the trash bin.

Arne
Sep 14 '07 #8

P: n/a
Ed
On Sep 13, 5:14 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
Ed wrote:
On Sep 13, 2:08 am, kcwong <evilwar...@gmail.comwrote:
To be fair,
Lew's reply contains *more* information than Roedy's.
I don't need more info! If I need more info, I could have spent hours
surfing the internet, and reading all about the String class and the
XML specification.
I am not a Student and don't have a time, I am a Programmer, and
wanted to resolve my current task!

Why ?

If you are not able to lookup some methods in the Java API docs
quicker than posting to usenet, then there are no point in
writing any code - the result should go directly to the trash bin.

Arne
That is your opinion, jackass!

Sep 14 '07 #9

P: n/a
On Sep 14, 1:34 pm, Ed <aru...@yahoo.comwrote:
<snip endless stream of uncalled for insults from Ed>

At this point, one has to wonder that if Ed really has a question to
ask, or is he started this thread just to troll.

In any case I don't think Ed will get any more answers from this group.

Sep 14 '07 #10

P: n/a
Ed wrote:
For your info, you may even be using a Java IDE Compiler written by my
friends!
What is a "Java IDE Compiler". Sounds very interesting. It it a compiler
that generates Java IDE's from meta language or is it a compiler that
generates any IDE from meta language using a compiler written in Java ?

Arne
Sep 15 '07 #11

P: n/a
Reminder: Feeding trolls only encourages them.

If you're gonna continue to argue with Ed, I strongly suggest you take
it to e-mail, or at least limit it to one newsgroup rather than pissing
in *two* communities' swimming pools.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Sep 16 '07 #12

P: n/a
Joshua Cranmer wrote:
In answer to your last question, perusing his headers indicates that Mr.
Pitts is using an en-US-localized Firefox build, therefore it is safe to
assume that he is working in the US.
I would not assume that.

A lot of people outside the US prefer to run UK or US versions of
all software.

Arne
Sep 16 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.