<?xml version='1.0'?>
<!DOCTYPE slides SYSTEM "slides.dtd">
<slides>
<foil>
<title>XML Basics</title>
<itemizedlist>
<listitem>
XML is a standard for defining
markup languages.
</listitem>
<listitem>
XML defines the <emphasis>syntax</emphasis>
of markup.
</listitem>
</itemizedlist>
</foil>
</slides>
<?xml version='1.0'?>.slides is the document root name and
the DTD is stored in an external file
slides.dtd. slides,
whose opening tag must appear on the first line of the XML.foil, title
or itemizedlist) must begin with a letter or underscore and can
include digits, hyphens, and periods.
<?xml version='1.0'?>
<!DOCTYPE slides SYSTEM "slides.dtd">
<slides>
<foil>
<title>XML Basics
<itemizedlist>
<listitem>
Salad < Fish & Chips
</LISTITEM>
<listitem>
XML defines <bold> the
<emphasis>syntax</bold></emphasis>
of markup.
</listitem>
</itemizedlist>
</foil>
</slides>
Errors in the above are:
We're only going to consider DTDs in this unit and then only at a very superficial level of detail. The important message is that there are ways to define the structure and content of XML documents.
DTD defines:
#PCDATA -- parsed character
data, entity references will be
replaced #CDATA -- character data, can contain
special chars
<!ELEMENT slides (foil+|section+)>
<!ATTLIST slides
"label CDATA #IMPLIED
status CDATA #IMPLIED
id ID #IMPLIED
revisionflag (changed | added | deleted | off) #IMPLIED">
<!ELEMENT section (title,foil+)>
<!ELEMENT foil (title,(itemizedlist|para))>
<!ELEMENT itemizedlist (listitem+)>
<!ELEMENT listitem #PCDATA>
<!ELEMENT para #PCDATA>
<!ENTITY comp249 "COMP249 (Web Technology)">
<!ENTITY copy "©">
<!ELEMENT element_name (names of child elements)>
<!ELEMENT slides (foil+|section+)>
+ - one or more occurrences* - zero or more occurrences? - zero or one occurrence. #PCDATA. <!ATTLIST element_name attribute_name attribute_type [default_value]>
<!ATTLIST slides label CDATA #IMPLIED>
#FIXED - the value, which every element will have and which
cannot be changed#REQUIRED - no default value is given; every instance of the
element must specify a value #IMPLIED - no default value is given; the value may or
may not be specified in an element.<!ENTITY entity_name "entity_value">
<!ENTITY comp249 "COMP249 (Web Technology)">
I'm studying &comp249;
<xml version="1.0" encoding="ISO-8859-1"?>
<rss version="0.91">
<channel>
<title>Announcements for COMP249</title>
<link>http://www.comp.mq.edu.au/units/comp249/cgi-bin/news</link>
<description>
This is an news service for COMP249 units established by Steve Cassidy.
</description>
<language>en-us</language>
<item>
<title>ANZAC Day Tutorials</title>
<link>http://www.comp.mq.edu.au/units/comp249/cgi-bin/news/2004/04/28#anzac-tut.txt</link>
<description>
If you missed a tutorial this week because of the ANZAC day holiday.
Please try to attend another session or submit your work directly to
your tutor for assessment.
</description>
</item>
<item>
<title>Assignment 3</title>
<link>http://www.comp.mq.edu.au/units/comp249/cgi-bin/news/2004/04/23#ass3.txt</link>
<description>
Assignment 3 is now available.
</description>
</item>
<item>
<title>Assignment 1 Marks</title>
<link>http://www.comp.mq.edu.au/units/comp249/cgi-bin/news/2004/04/16#ass1marks.txt</link>
<description>
Marks for Assignment 1 have been sent to your ics email address (s123456@ics.mq.edu.au).
</description>
</item>
</channel>
</rss>
Web browsers store bookmarks in a variety of formats, some provide tools to import bookmarks from other browsers, but often you can't go back again. XBEL acts as an intermediate format between the Internet Explorer, Netscape and other formats.
title,
description, info, metadata.
<?xml version="1.0"?>
<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML"
"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd">
<xbel>
<info>
<metadata owner="Norman Walsh <ndw@nwalsh.com>" />
</info>
<folder id="perlbookmarks">
<title>Perl</title>
<bookmark href="http://www.perl.com/">
<title>Perl.com</title>
</bookmark>
<bookmark href="http://www.activestate.com/">
<title>ActiveState Tool Corp. (Perl for Win32)</title>
</bookmark>
<bookmark href="http://194.247.167.1/DADA/PERL/">
<title>dada meets Perl!</title>
</bookmark>
</folder>
</xbel>
<?xml version="1.0" encoding="ISO-8859-1"?>
<vxml version="2.0" lang="en">
<form>
<field name="city">
<prompt> Where do you want to travel to? </prompt>
<option> Edinburgh </option>
<option> New York </option>
<option> London </option>
<option> Paris </option>
<option> Stockholm </option>
</field>
<field name="travellers" type="number">
<prompt> How many are travelling to <value expr="city"/>? </prompt>
</field>
<block>
<submit next="http://localhost/handler" namelist="city travellers"/>
</block>
</form>
</vxml>
{
"Name": "John Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
},
"phoneNumbers": [ "212 555-1234", "646 555-4567" ]
}
var parser=new DOMParser();
var doc=parser.parseFromString(txt,"text/xml");
/* now access elements using the DOM API */
to = doc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
Source: w3schools
var p = eval("(" + JSON_text + ")");
/* or using a parser (safer) */
var p = json_parse(JSON_text);
/* now access the data elements */
to = p.to