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

JDOM and &qout;

P: n/a
Hi all,
i used JDOM to create XML file.
first, i get data from database and create Document object. in some data i
have quotas, so it makes replacment in content of elements. for example:
if i have "Hi" in database, i will have "Hi" in content of
element. And it is ok, because in xml does not exist ", at least i think
that.
After it i want to make convert from document to string. I used

XMLOutputter serializer = new XMLOutputter();
String output = serializer.outputString(document);

now, when i look what's happened with "Hi" i found following
string
"Hi"
it makes conversion of & again, and that is not ok.

has someone similiar problem? or do you know how to solve it?

i can make parsing of string again and cut what is wrong, but is it possible
to set something without that?

thanks in advance.
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
mali_djuro wrote:
Hi all,
i used JDOM to create XML file.
first, i get data from database and create Document object. in some data i
have quotas, so it makes replacment in content of elements. for example:
if i have "Hi" in database, i will have "Hi" in content of
element. And it is ok, because in xml does not exist ", at least i think
that.
After it i want to make convert from document to string. I used

XMLOutputter serializer = new XMLOutputter();
String output = serializer.outputString(document);

now, when i look what's happened with "Hi" i found following
string
"Hi"
it makes conversion of & again, and that is not ok.

has someone similiar problem? or do you know how to solve it?

i can make parsing of string again and cut what is wrong, but is it possible
to set something without that?


Friend,

It is likely that the good people at JDOM have already considered your
problem and are accounting for it themselves. So, it is probably safe
to simply pass "Hi" directly to the JDOM API without prior escaping.

Ray

Jul 17 '05 #2

P: n/a
Hi,
i didn't understand you.
i need to create document object and than transform it to string, or file.

if you have some examples please write to me.

thanks.

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:AG******************@twister.nyroc.rr.com...
mali_djuro wrote:
Hi all,
i used JDOM to create XML file.
first, i get data from database and create Document object. in some data i have quotas, so it makes replacment in content of elements. for example:
if i have "Hi" in database, i will have &quot;Hi&quot; in content of
element. And it is ok, because in xml does not exist ", at least i think
that.
After it i want to make convert from document to string. I used

XMLOutputter serializer = new XMLOutputter();
String output = serializer.outputString(document);

now, when i look what's happened with &quot;Hi&quot; i found following
string
&amp;quot;Hi&amp;quot;
it makes conversion of & again, and that is not ok.

has someone similiar problem? or do you know how to solve it?

i can make parsing of string again and cut what is wrong, but is it possible to set something without that?


Friend,

It is likely that the good people at JDOM have already considered your
problem and are accounting for it themselves. So, it is probably safe
to simply pass "Hi" directly to the JDOM API without prior escaping.

Ray

Jul 17 '05 #3

P: n/a
mali_djuro wrote:
Hi,
i didn't understand you.
i need to create document object and than transform it to string, or file.

if you have some examples please write to me.

thanks.

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:AG******************@twister.nyroc.rr.com...
mali_djuro wrote:
Hi all,
i used JDOM to create XML file.
first, i get data from database and create Document object. in some data
i
have quotas, so it makes replacment in content of elements. for example:
if i have "Hi" in database, i will have &quot;Hi&quot; in content of
element. And it is ok, because in xml does not exist ", at least i think
that.
After it i want to make convert from document to string. I used

XMLOutputter serializer = new XMLOutputter();
String output = serializer.outputString(document);

now, when i look what's happened with &quot;Hi&quot; i found following
string
&amp;quot;Hi&amp;quot;
it makes conversion of & again, and that is not ok.

has someone similiar problem? or do you know how to solve it?

i can make parsing of string again and cut what is wrong, but is it
possible
to set something without that?


Friend,

It is likely that the good people at JDOM have already considered your
problem and are accounting for it themselves. So, it is probably safe
to simply pass "Hi" directly to the JDOM API without prior escaping.

Ray


Please do not top post, especially in reply to someone who has bottom
posted.

If you wish more specific advise, you will have to supply more specific
code yourself. For example, what is document in your code above?
Ideally, you should post the smallest possible complete program that
exhibits the issue you are having. Provide the expected and actual
outputs. I suspect you will be most pleased from the response of the group.

Ray

Jul 17 '05 #4

P: n/a

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:tI*******************@twister.nyroc.rr.com...
mali_djuro wrote:
Hi,
i didn't understand you.
i need to create document object and than transform it to string, or file.
if you have some examples please write to me.

thanks.

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:AG******************@twister.nyroc.rr.com...
mali_djuro wrote:

Hi all,
i used JDOM to create XML file.
first, i get data from database and create Document object. in some data

i
have quotas, so it makes replacment in content of elements. for
example:if i have "Hi" in database, i will have &quot;Hi&quot; in content of
element. And it is ok, because in xml does not exist ", at least i thinkthat.
After it i want to make convert from document to string. I used

XMLOutputter serializer = new XMLOutputter();
String output = serializer.outputString(document);

now, when i look what's happened with &quot;Hi&quot; i found following
string
&amp;quot;Hi&amp;quot;
it makes conversion of & again, and that is not ok.

has someone similiar problem? or do you know how to solve it?

i can make parsing of string again and cut what is wrong, but is it


possible
to set something without that?
Friend,

It is likely that the good people at JDOM have already considered your
problem and are accounting for it themselves. So, it is probably safe
to simply pass "Hi" directly to the JDOM API without prior escaping.

Ray


Please do not top post, especially in reply to someone who has bottom
posted.

If you wish more specific advise, you will have to supply more specific
code yourself. For example, what is document in your code above?
Ideally, you should post the smallest possible complete program that
exhibits the issue you are having. Provide the expected and actual
outputs. I suspect you will be most pleased from the response of the

group.
Ray


sorry, ray.
i didn't think when i answered on your post.
i am back on my problem:

function transformXMLToString(){

//here, i got some object
SomeObject so = new SomeObject();
so.setName("mali");
so.setHi("\"Hi\""); // here i have value of so.hi = "Hi" with qoutas

//now i make Document object

Element root = new Element("mainNode");
String output = new String();
Document document = new Document(root);
try{
//NodeName
Element sub = new Element("nodeName");
sub.addContent(so.getName());
root.addContent(prom);

//NodeHi
sub = new Element("NodeHi");
sub.addContent(so.getHi()); //content of sub is &quot;Hi&quot;
root.addContent(prom);

XMLOutputter serializer = new XMLOutputter();
output = serializer.outputString(document);

}
catch(Exception e){
System.out.println(e.getMessage());
}
return output;
}

so, for output i get
<?xml version="1.0"?>
<nodeMain>
<NodeName>mali</NodeName>
<NodeHi>&amp;quot;Hi&amp;quot;</NodeHi>
</nodeMain>

but i want for output following string
<?xml version="1.0"?>
<nodeMain>
<NodeName>mali</NodeName>
<NodeHi>&quot;Hi&quot;</NodeHi>
</nodeMain>
thanks
Jul 17 '05 #5

P: n/a
mali_djuro wrote:

function transformXMLToString(){

//here, i got some object
SomeObject so = new SomeObject();
so.setName("mali");
so.setHi("\"Hi\""); // here i have value of so.hi = "Hi" with qoutas

//now i make Document object

Element root = new Element("mainNode");
String output = new String();
Document document = new Document(root);
try{
//NodeName
Element sub = new Element("nodeName");
sub.addContent(so.getName());
root.addContent(prom);

//NodeHi
sub = new Element("NodeHi");
sub.addContent(so.getHi()); //content of sub is &quot;Hi&quot;
root.addContent(prom);

XMLOutputter serializer = new XMLOutputter();
output = serializer.outputString(document);

}
catch(Exception e){
System.out.println(e.getMessage());
}
return output;
}

so, for output i get
<?xml version="1.0"?>
<nodeMain>
<NodeName>mali</NodeName>
<NodeHi>&amp;quot;Hi&amp;quot;</NodeHi>
</nodeMain>

but i want for output following string
<?xml version="1.0"?>
<nodeMain>
<NodeName>mali</NodeName>
<NodeHi>&quot;Hi&quot;</NodeHi>
</nodeMain>
thanks


It would be best if you provide a complete program. That would allow
other to run and debug it.

Since I do not know what is happening in the SomeObject class, I cannot
know what is really being passed to the JDOM classes. I would focus on
exactly what is being passed to sub.addContent().

Ray

Jul 17 '05 #6

P: n/a
import java.util.Random;
public class name
{
public static void main(String[] args)
{
String string1;
char char1 = 7;
string1 = " ";
int temp, length;
Random generator = new Random();
length = generator.nextInt(10);
for(int blah = 0;blah <= length;blah++)
{
temp = generator.nextInt(26);
if(temp == 1)
char1 = 65;
if(temp == 2)
char1 = 66;
if(temp == 3)
char1 = 67;
if(temp == 4)
char1 = 68;
if(temp == 5)
char1 = 69;
if(temp == 6)
char1 = 70;
if(temp == 7)
char1 = 71;
if(temp == 8)
char1 = 72;
if(temp == 9)
char1 = 73;
if(temp == 10)
char1 = 74;
if(temp == 11)
char1 = 75;
if(temp == 12)
char1 = 76;
if(temp == 13)
char1 = 77;
if(temp == 14)
char1 = 78;
if(temp == 15)
char1 = 79;
if(temp == 16)
char1 = 80;
if(temp == 17)
char1 = 81;
if(temp == 18)
char1 = 82;
if(temp == 19)
char1 = 83;
if(temp == 20)
char1 = 84;
if(temp == 21)
char1 = 85;
if(temp == 22)
char1 = 86;
if(temp == 23)
char1 = 87;
if(temp == 24)
char1 = 88;
if(temp == 25)
char1 = 89;
if(temp == 26)
char1 = 90;
string1 = string1 + char1;
}
System.out.println(string1);
}
}
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.