473,938 Members | 8,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use Javascript to assemble a XML file?

TPK
Is there any way javascript can be used to assemble a XML file?

Any resources out there that may explain how to do this (if possible)?

TPK

Oct 31 '06 #1
2 1489

TPK wrote:
Is there any way javascript can be used to assemble a XML file?

Any resources out there that may explain how to do this (if possible)?

TPK
Hi

The answer is yes.

JavaScript generally has no native XML handling (although there is an
extension to Firefox which implements E4X I think :
<URL:http://www.ecma-international.o rg/publications/standards/Ecma-357.htm>)

However, the latest web browsers all provide a host objects/ActiveX
objects which Javascript can access to create XML documents.

If I type in "Javascript and XML" in google, I get approximately 34
million responses, and there are probably just as many posts on the
subject if you search this newsgroup. I suggest you start by doing
some searching and following up a few of those yourself.

The cross-browser Sarissa Javascript library is also useful to look at,
or the zXML library provided by <URL:http://www.nczonline.n et>.

Regards

Julian Turner

Oct 31 '06 #2
TPK wrote:
Is there any way javascript can be used to assemble a XML file?

Any resources out there that may explain how to do this (if possible)?
You can use the DOM to build an in memory XML DOM document. Saving to a
local file is usually (meaning in the browser sandbox) not possible but
you can use XMLHttpRequest so send such a DOM document to your server.

var xmlDocument = null;

if (document.imple mentation && typeof
document.implem entation.create Document != 'undefined') {
xmlDocument = document.implem entation.create Document('', 'dummy', null);
}
else if (typeof ActiveXObject != 'undefined') {
try {
xmlDocument = new ActiveXObject(' Msxml2.DOMDocum ent');
}
catch (e) {
try {
xmlDocument = new ActiveXObject(' Microsoft.XMLDO M');
}
catch (e) {}
}
}

if (xmlDocument != null) {
var root = xmlDocument.cre ateElement('god s');
if (xmlDocument.do cumentElement) {
xmlDocument.rep laceChild(root, xmlDocument.doc umentElement);
}
else {
xmlDocument.app endChild(root);
}
var god = xmlDocument.cre ateElement('god ');
god.appendChild (xmlDocument.cr eateTextNode('K ibo'));
root.appendChil d(god);
if (typeof XMLSerializer != 'undefined') {
alert(new XMLSerializer() .serializeToStr ing(xmlDocument ));
}
else {
alert(xmlDocume nt.xml);
}
}

createDocument is W3C DOM Level 2 Core to create an XML DOM document.
That method wants the tag name (and namespace) of the root element so
the newly created document has already a root element. The method is
supported by browsers like Mozilla/Firefox, Opera 8/9.
new ActiveXObject(' Msxml2.DOMDocum ent') (respectively new
ActiveXObject(' Microsoft.XMLDO M')) is for IE/Win using MSXML to create
an XML DOM document which is empty.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
5847
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
13
4306
by: Craig | last post by:
Hey all, Here's the situation: - two websites, one on domain1 and the other on domain2 - domain1 opens a new window which is a javascript app from domain2 - domain1 needs to communicate with the javascript app on domain2 The problem occurs in that last step. Browsers don't allow script access across domains for security reasons, rightly so. Nonetheless, I still
1
2760
by: it hates me | last post by:
Hey gang, I hope you're all well and you're having an enjoyable week I'd love to be able to have a custom news feed on my web page through Javascript The only custom news feed I can find for free is from Yahoo. Are there any more? Now, for my web page I can get this to work fine:
136
9539
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
1
1933
by: Mike Walters | last post by:
Reading the current Namespace.Class, Assemble at runtime I am trying to get the Assemble, Namespace and Class name of a form at runtime. I have several assembles and namespaces in my app, I need to determine what namespace.class, assemble I am currently processing. Thanks Mike Walters
0
862
by: Just Me | last post by:
When I try to add an AddressControl usercontrol to a form I get the message. An exception occurred while trying to create an instance of AddressControlNS.AddressControl... The exception was "File or assemble name CsLibrary, or one of its dependendecies was not found. The project for CsLibrary is in the same solution (but not the same as the project containing the form).
2
3236
by: Alan Silver | last post by:
Hello, I have just discovered that if you turn off Javascript, then cross-page posting does not work. The postback goes to the originating page, which basically means that nothing happens. I thought the whole framework was supposed to degrade gracefully in cases like this? AFAIK other features work fine without Javascript, why doesn't this?
3
2129
by: DanG | last post by:
Hi I used to have an ImageButton in my datagrid, and referenced the control in the javascript with: var fld = document.getElementById('datagrid__ctl2_btnEdit'); alert(fld); //returns "" >Good I changed the ImageButton to a LinkButton, but the javascript doesn't work anymore. var fld = document.getElementById('datagrid__ctl2_btnEdit'); //Same as
3
1895
by: starffly | last post by:
I overloaded operator+ in a class, and I want to invoke this operator in inline assemble like this: _asm call operator+ but it cannot be complied OK. compiler says there are some illegalI opcodes, and I'm absolutely sure that all the other codes are OK. actually I don't know how to invoke overloaded operator in inline assamble, I write this referring to the deassemble code by vc. who can tell me how to invoke overloaded operator...
0
10125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9963
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11512
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11098
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10649
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9853
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6072
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3495
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.