I am battling to work / understand XML. Where can I find good clear help or tutorials on the topic? I am working in JavaScript.
Thanks
I am battling to work / understand XML. Where can I find good clear help or tutorials on the topic? I am working in JavaScript.
Thanks
Do you have problems in understanding XML itself or how to read/write it? XML is a really simple but powerful language. Actually there are multiple ways of storing data in it. Some put their data values inside an element as text-node others (like me) prefer to put them as attributes into an element.
Here some example elements:
// a simple element without a body
//<ElementName/>
//
// a normal element with body
//<ElementName> body </ElementName>
//
// another empty element without a body but an attribute
//<ElementName AttributeName="AttributeValue" />
There are some rules you should keep in mind:
To read or write an xml file there are multiple possibilities. The most common way is to use a DOM-node-tree to represent the xml in memory. Another way (which might be a bit more advanced) is to use a SAX-parser which invokes callback routines for every element it parses.
SAX is great if the file is huge and you don't want to have the whole file as DOM in memory. But in most cases DOM is the easiest way.
In .NET or mono there are some special classes that represents a whole xml file as DOM tree. `XmlDocument` and `XmlElement` is what you need.
In JS (in C# as well) you need to include the xml namespace in order to use those classes.
// JS
import System.Xml;
// C#
using System.Xml;
If you have specific problems just ask ;)
I used the XmlReader class to read an XML-file and load the tree into an object I could work with. Is your XML in a file? If so, take a look at this tutorial:
http://msdn.microsoft.com/en-us/library/aa720470%28v=vs.71%29.aspx
If your XML is from a Stream, there's an explanation here:
http://support.microsoft.com/kb/301228
I apologize that these articles are in C# and not JavaScript. The same principles should apply, though.
Save - load script settings from xml
Download :
https://docs.google.com/open?id=0B0aMXRZ2PWXZQjhKMXdDLVJLZDA