XML

From Fab Lab Bcn WIKI
Revision as of 10:58, 7 December 2011 by Guillem (Talk | contribs)

Jump to: navigation, search

Extensible Markup Language (XML) is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification<ref>Template:Cite web</ref> produced by the W3C, and several other related specifications, all gratis open standards.<ref>Template:Cite web</ref>

The design goals of XML emphasize simplicity, generality, and usability over the Internet.<ref name="XML Goals">Template:Cite web</ref> It is a textual data format with strong support via Unicode for the languages of the world. Although the design of XML focuses on documents, it is widely used for the representation of arbitrary data structures, for example in web services.

Many application programming interfaces (APIs) have been developed that software developers use to process XML data, and several schema systems exist to aid in the definition of XML-based languages.

Edit and create

Parsing

Processing

Example


The following short XML file called "sites.xml" is parsed in the code below. It must be in the project's "data" directory

<?xml version="1.0"?> <websites> <site id="0" url="processing.org">Processing</site> <site id="1" url="mobile.processing.org">Processing Mobile</site> </websites>

XMLElement xml;

void setup() {

 size(200, 200);
 xml = new XMLElement(this, "sites.xml");
 int numSites = xml.getChildCount();
 for (int i = 0; i < numSites; i++) {
   XMLElement kid = xml.getChild(i);
   int id = kid.getInt("id"); 
   String url = kid.getString("url"); 
   String site = kid.getContent();
   println(id + " : " + url + " : " + site);    
 }

}