W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2011

[whatwg] Requesting JSON.toXML

From: Charles Pritchard <chuck@jumis.com>
Date: Fri, 30 Sep 2011 15:03:21 -0700
Message-ID: <4E863CA9.3060406@jumis.com>
On 9/30/11 2:57 PM, Tab Atkins Jr. wrote:
> On Fri, Sep 30, 2011 at 2:52 PM, Charles Pritchard<chuck at jumis.com>  wrote:
>> On Sep 30, 2011, at 2:23 PM, "Tab Atkins Jr."<jackalmage at gmail.com>  wrote:
>>> On Fri, Sep 30, 2011 at 2:19 PM, Charles Pritchard<chuck at jumis.com>  wrote:
>>>> Now that DOM4 includes DOMString as an argument type for Node methods, I'd like to have a clear and easy path to serialize a JSON object into an XML DOMString.
>>>>
>>>> It's not a trivial task. Any takers?
>>>>
>>>> Example:
>>>>
>>>> JSON.toXML({div:'Hello world'});
>>> I'm curious why you would want such a thing.  You can store DOM trees
>>> as strings and revive them when used.  You can transmit DOM across XHR
>>> either as a string or, soon, directly as a document.
>>>
>>> I don't see a reason to store DOM into an alternative JSON structure.
>> JSON is widely more popular than XML for a lot of APIs. People use JSON.stringify an parse quite a bit. I may be misunderstanding what it is you mean by DOM.
> The first paragraph of your original email talked about the Node
> methods now accepting DOMStrings.  Since you then asked for a way to
> convert JSON to a DOMString, I reasonably assumed the two statements
> were related.
>
> I guess I should be more direct, then.  What problem are you
> attempting to solve with this feature?

I'd like to skip the population of a DOM via: for(var i in obj) { 
dom.appendChild(i);.... };

Anne has "overloaded Node.appendChild" with DOMString.
That makes appendChild('<div>hello world</div'); easier.  That's my 
understanding, anyway.

I'm trying to solve the appendChild({div: 'hello world'}); syntax that 
we were trying to address with Element.create.

I know that a JSON.toNode with XSL or other selectors could be a nice 
way of doing things in the future, similar to Microsoft's LINQ (but 
different).

JSON is widely used, it's quite useful, and it'd be nice to have better 
integration between JSON and DOM+XML.

Using JS objects as a means of populating has been discussed repeatedly 
for use with SVG.

Having looked at this again, I'd really prefer to have something like 
Node JSON.toNode(obj) over DOMString JSON.toXML(obj).

-Charles
Received on Friday, 30 September 2011 15:03:21 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:36 UTC