put XML document in json

M

MD

I want to put the xml document into the JSON like the following.

[
{
"id" : "123333",
"xmldoc": "<? xml version=\"1.0\" ?><data><link></link></data>";
},
{
"id" : "123334",
"xmldoc": "<? xml version=\"1.0\" ?><data><link></link></data>";
},
]

However, usually my xml document has new line for the xml document. Is there
any option to skip the new line in the JSON or I just have to remove them
manually .


MD
 
M

MD

Thanks for reply,

However, I don't want to conver to any format but json.
We have xml document for each record in oracle xml type,
I just want to get it and pass to the browser from servlet as a search
result.

[
 
T

Tom Cole

drclue said:
MD said:
Thanks for reply,

However, I don't want to conver to any format but json.
We have xml document for each record in oracle xml type,
I just want to get it and pass to the browser from servlet as a search
result.

[
{
"id" : "123333",
"xmldoc": "<? xml version=\"1.0\" ?><data><link></link></data>";
},
{
"id" : "123334",
"xmldoc": "<? xml version=\"1.0\" ?><data><link></link></data>";
},
]

Both your sample here and the one I gave are JASON.

Just for future reference, it's JSON (I went to school with a Jason,
though). Wouldn't want you to put JASON on a job application or
anything, might loose some "cred" with the employer...

I once had a friend ask me if I'd heard anything about some new
technology called Rudy on Rails. I snickered (inside of course).
 
M

Martin Honnen

MD wrote:

However, usually my xml document has new line for the xml document. Is there
any option to skip the new line in the JSON or I just have to remove them
manually .

I am not sure I understand the problem, if you build JSON with
<http://www.json.org/json.js>
then the result you get for e.g.
var s = ['<gods>', '<god>Kibo</god>', '</gods>'].join('\r\n');
var obj = { xml: s };
obj.toJSONString()
is
{"xml":"<gods>\r\n<god>Kibo</god>\r\n</gods>"}
so all line break/carriage return characters are properly escaped.
Simply use that library or the proper library for other languages (e.g.
PHP) to create your JSON data and line breaks/carriage returns in
strings (of XML or otherwise) should not be a problem, they will simply
be escaped as needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top