This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes xml and javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "xml and javascript" Watch "xml and javascript" New topic
Author

xml and javascript

Veshnu Ramakrishnan
Ranch Hand

Joined: Sep 27, 2005
Posts: 44
I need to create an xml object using javascript. like create node attributes etc and send it through ajax. i need to know about the xml manipulation methods and objects in javascript. can anyone help me in this


Veshnu<br />SCBCD<br />SCWCD<br />SCJP
Christian Gross
Author
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
To manipulate XML in JavaScript you have to deal with the different instantiation methods in XML.

To create an XML document in IE:

var xmlDoc = new ActiveXObject( "Microsoft.XmlDom");

To load something in the document you can load it by referencing the file
xmlDoc.load( URL), or
xmlDoc.load( str) where str is a valid XML document.

The result is an XML DOM document that can be manipulating like the XML DOM.

In Mozilla you need the following line
var xmlDoc = document.implementation.createDocument( namespace, rootElement, null);

The result is an XML document with namespace, and rootElement that can be manipulated using the standard XML DOM methods.

For exact details of the methods I would reference the XML DOM documentation.

Then to save the XML to a string, for IE you use the xml property associated with a node, and for Mozilla you use the XMLSerializer object.

Christian
[ February 24, 2006: Message edited by: Christian Gross ]

Author of Ajax Patterns and Best Practices
 
wood burning stoves
 
subject: xml and javascript
 
Similar Threads
Unexpected call to method or property access.
parsers for javascript
advise on using XML in the application
JDOM in Javascripts?
constructing xml from values in database