Connecting Tech Pros Worldwide Forums | Help | Site Map

XMLHttpRequest for *creating* XML documents?

William
Guest
 
Posts: n/a
#1: Jun 16 '06
Heya,

I have been looking all over Google for ways to *create* an XML document
using any Javascript object, and it seems that no one has ever tried or
ever needed this.

I want to send the server some info dynamically created on the page, and
instead of sending a complicated GET request with the info, or creating
an XML using my own set of functions, is there any object that allows
you to use the Document Object Model, like adding nodes, etc, and then
output the XML text at the end you could then send to the server? It
seems XMLHttpRequest is only for requests, and I don't want to use
Microsoft-only ActiveX XML objects.

Any idea?

Thanks,

------
William

NetOne
Guest
 
Posts: n/a
#2: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?


XMLHttpRequest is supported on various browsers nowadays, although in
different ways.

William wrote:[color=blue]
> Heya,
>
> I have been looking all over Google for ways to *create* an XML document
> using any Javascript object, and it seems that no one has ever tried or
> ever needed this.
>
> I want to send the server some info dynamically created on the page, and
> instead of sending a complicated GET request with the info, or creating
> an XML using my own set of functions, is there any object that allows
> you to use the Document Object Model, like adding nodes, etc, and then
> output the XML text at the end you could then send to the server? It
> seems XMLHttpRequest is only for requests, and I don't want to use
> Microsoft-only ActiveX XML objects.
>
> Any idea?
>
> Thanks,
>
> ------
> William[/color]

RobG
Guest
 
Posts: n/a
#3: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?


William wrote:[color=blue]
> Heya,
>
> I have been looking all over Google for ways to *create* an XML document
> using any Javascript object, and it seems that no one has ever tried or
> ever needed this.[/color]

Look a little harder ;-) try the W3 Load and Save spec:

"a platform- and language-neutral interface that allows programs
and scripts to dynamically load the content of an XML document
into a DOM document and serialize a DOM document into an
XML document"

<URL:http://www.w3.org/TR/DOM-Level-3-LS/>

However it's not well supported by browsers yet - at least it gives you
a starting point. There's some info here:

<URL:http://developer.mozilla.org/en/docs/XML_in_Mozilla#DOM_Load_and_Save_Methods>


--
Rob

Laurent Bugnion
Guest
 
Posts: n/a
#4: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?


Hi,

William wrote:[color=blue]
> Heya,
>
> I have been looking all over Google for ways to *create* an XML document
> using any Javascript object, and it seems that no one has ever tried or
> ever needed this.
>
> I want to send the server some info dynamically created on the page, and
> instead of sending a complicated GET request with the info, or creating
> an XML using my own set of functions, is there any object that allows
> you to use the Document Object Model, like adding nodes, etc, and then
> output the XML text at the end you could then send to the server? It
> seems XMLHttpRequest is only for requests, and I don't want to use
> Microsoft-only ActiveX XML objects.
>
> Any idea?
>
> Thanks,
>
> ------
> William[/color]

The XML objects are not IE only, see
http://www.quirksmode.org/dom/importxml.html
for a cross-browser example. I implemented the example and tested in
Firefox, it works. Is that what you're looking for?

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Martin Honnen
Guest
 
Posts: n/a
#5: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?




William wrote:

[color=blue]
> I have been looking all over Google for ways to *create* an XML document
> using any Javascript object, and it seems that no one has ever tried or
> ever needed this.[/color]


Mozilla and Opera support the W3C DOM Level 2
var xmlDocument = document.implementation.createDocument('',
'root-element', null)
to start from scratch.

Then they both support DOMParser to start with parsing a string e.g.
var xmlDocument = new DOMParser().parseFromString(
'<gods><god>Kibo</god></gods>',
'application/xml'
);

--

Martin Honnen
http://JavaScript.FAQTs.com/
William
Guest
 
Posts: n/a
#6: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?


Thanks, but if you read my message, I was saying that it doesnt support
creating XML documents, which is really want I want to do....


-----
William

NetOne wrote:[color=blue]
> XMLHttpRequest is supported on various browsers nowadays, although in
> different ways.
>
> William wrote:[color=green]
>> Heya,
>>
>> I have been looking all over Google for ways to *create* an XML document
>> using any Javascript object, and it seems that no one has ever tried or
>> ever needed this.
>>
>> I want to send the server some info dynamically created on the page, and
>> instead of sending a complicated GET request with the info, or creating
>> an XML using my own set of functions, is there any object that allows
>> you to use the Document Object Model, like adding nodes, etc, and then
>> output the XML text at the end you could then send to the server? It
>> seems XMLHttpRequest is only for requests, and I don't want to use
>> Microsoft-only ActiveX XML objects.
>>
>> Any idea?
>>
>> Thanks,
>>
>> ------
>> William[/color]
>[/color]
William
Guest
 
Posts: n/a
#7: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?


Thanks, but I've seen it, and it says:
[color=blue]
> Mozilla currently implements only the load() method[/color]

Not really helpful, cross platform solution I would say....

-------
William

RobG wrote:[color=blue]
> William wrote:[color=green]
>> Heya,
>>
>> I have been looking all over Google for ways to *create* an XML document
>> using any Javascript object, and it seems that no one has ever tried or
>> ever needed this.[/color]
>
> Look a little harder ;-) try the W3 Load and Save spec:
>
> "a platform- and language-neutral interface that allows programs
> and scripts to dynamically load the content of an XML document
> into a DOM document and serialize a DOM document into an
> XML document"
>
> <URL:http://www.w3.org/TR/DOM-Level-3-LS/>
>
> However it's not well supported by browsers yet - at least it gives you
> a starting point. There's some info here:
>
> <URL:http://developer.mozilla.org/en/docs/XML_in_Mozilla#DOM_Load_and_Save_Methods>
>
>[/color]
William
Guest
 
Posts: n/a
#8: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?


Thanks for the answer, but I've seen this before, and again, I want to
*create* and *save* a document in a browser in Javascript, not load one,
and this example doesnt explain creating and saving an XML, just loading
one. I need something like:

var obj = new XMLDoc();
var item = obj.AddNode(a);
var item2 = obj.AddNode(b);
var xml = obj.contentXml;

and then be able to send this to a PHP page through XMLHttpRequest or
whatever.

So please if someone ever created and saved in a variable some XML text
created using DOM on a browser, let me know. I'm not talking about
making my own function to create the XML, but this is what I might end
up doing. I just thought it would be cleaner to use a DOM object, which
is more consistent with other widely used techniques.

-----
William

Laurent Bugnion wrote:[color=blue]
> Hi,
>
> William wrote:[color=green]
>> Heya,
>>
>> I have been looking all over Google for ways to *create* an XML
>> document using any Javascript object, and it seems that no one has
>> ever tried or ever needed this.
>>
>> I want to send the server some info dynamically created on the page,
>> and instead of sending a complicated GET request with the info, or
>> creating an XML using my own set of functions, is there any object
>> that allows you to use the Document Object Model, like adding nodes,
>> etc, and then output the XML text at the end you could then send to
>> the server? It seems XMLHttpRequest is only for requests, and I don't
>> want to use Microsoft-only ActiveX XML objects.
>>
>> Any idea?
>>
>> Thanks,
>>
>> ------
>> William[/color]
>
> The XML objects are not IE only, see
> http://www.quirksmode.org/dom/importxml.html
> for a cross-browser example. I implemented the example and tested in
> Firefox, it works. Is that what you're looking for?
>
> Greetings,
> Laurent[/color]
Martin Honnen
Guest
 
Posts: n/a
#9: Jun 16 '06

re: XMLHttpRequest for *creating* XML documents?




William wrote:

[color=blue]
> I need something like:
>
> var obj = new XMLDoc();[/color]

var xmlDoc = document.implementation.createDocument('',
'root-element', null);
[color=blue]
> var item = obj.AddNode(a);[/color]

var element = xmlDoc.createElement('child');
element.appendChild(xmlDoc.createTextNode('Kibolog y for all.'));
xmlDoc.documentElement.appendChild(element);
[color=blue]
> and then be able to send this to a PHP page through XMLHttpRequest[/color]

The send method takes a DOM node like a DOM XML document as the argument
so you can POST the xmlDoc created above to the server.

Code works with Mozilla and Opera at least, not sure about Safari,Konqueror.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jim Davis
Guest
 
Posts: n/a
#10: Jul 11 '06

re: XMLHttpRequest for *creating* XML documents?



"William" <william@metaNOyer.inSPAMfowrote in message
news:ylokg.12421$Ra3.115402@weber.videotron.net...
Quote:
Heya,
>
I have been looking all over Google for ways to *create* an XML document
using any Javascript object, and it seems that no one has ever tried or
ever needed this.
>
I want to send the server some info dynamically created on the page, and
instead of sending a complicated GET request with the info, or creating an
XML using my own set of functions, is there any object that allows you to
use the Document Object Model, like adding nodes, etc, and then output the
XML text at the end you could then send to the server? It seems
XMLHttpRequest is only for requests, and I don't want to use
Microsoft-only ActiveX XML objects.
DP_YODEL will convert a JavaScript object to an XML object using the YODEL
spec:

http://www.depressedpress.com/Conten...ODEL/Index.cfm

XML-RPC and WDDX are other (more popular, but since I wrote YODEL I gave it
top billing) options that have JavaScript serialization libraries.

In general this makes things pretty easy: you create a native JavaScript
object that represents the data you want to pass, pump it through a nice
black-box object which converts it to XML and pass it on up. The server
would have a related object which would deserialize the data.

Jim Davis



Closed Thread


Similar JavaScript / Ajax / DHTML bytes