Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > put XML document in json

Reply
Thread Tools

put XML document in json

 
 
MD
Guest
Posts: n/a
 
      09-14-2006
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


 
Reply With Quote
 
 
 
 
MD
Guest
Posts: n/a
 
      09-14-2006
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>";
> },
> ]




 
Reply With Quote
 
 
 
 
Tom Cole
Guest
Posts: n/a
 
      09-15-2006

drclue wrote:
> MD wrote:
> > 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).

> Mine is just all squeezed on one line, and has a couple of
> javascript calls tacked on the end.
>
> The other thing that differs between our approaches
> is that on the browser side , a single call to
> my JASON2XML() function turns my JASON result sets
> no matter the query back into XML that can be used with XSLT and
> other facilities in the browser.
>
> The orginal basic question you had I believe was about
> newlines. Answer: ( don't use them )
>
> The big sample result was just so you could see a live example
> and notice not only that is was devoid of newlines, but
> possibly answer other questions you might come across by having a live
> sample to reference.


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-15-2006


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-15-2006


drclue wrote:


> I think the OP's newline issue might actually be related not so much to
> the data itself , but rather spreading the JSON syntax over multiple
> lines of source which can cause parsing issues.


I think JSON allows white space like line breaks between
tokens/delimiters: <http://www.ietf.org/rfc/rfc4627.txt?number=4627>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc Acácio Centeno Python 1 02-15-2013 07:34 AM
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
"JSON for ASP" at json.org Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments