Show Menu
Cheatography

Xml Cheat Sheet (DRAFT) by

xml cheat sheet with syntax etc

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Syntax

<ro­ot>
  <child>
   <subchild>.....</subchild>
  </child>
</root>
<no­te>
  <to>Tove</to>
   <fr­om>­Jan­i</­fro­m>
  <heading>Reminder</heading>
  <body>Don't forget me this weeken­d!<­/bo­dy>
</note>

Commenting

<!-- This is a comment -->

Prolog

<?xml versio­n="1.0" encodi­ng=­"­UTF­-8"?>
UTF-8 is the default character encoding for XML documents.
The XML prolog is optional.

Entity References

<
&lt;
>
&gt;
&
&amp;
'
&apos;
"
&quot;

HttpRe­quest

The first line in the example above creates an XMLHtt­pRe­quest object:
var xhttp = new XMLHtt­pRe­que­st();
The onread­yst­ate­change property specifies a function to be executed every time the status of the XMLHtt­pRe­quest object changes:
xhttp.o­nr­ead­yst­ate­change = function()
When readyState property is 4 and the status property is 200, the response is ready:
if (this.r­ea­dyState == 4 && this.s­tatus == 200)
The respon­seText property returns the server response as a text string.The text string can be used to update a web page:
docume­nt.g­et­Ele­men­tBy­Id(­"­dem­o").i­nn­erHTML = xhttp.r­es­pon­seText;
var xhttp = new XMLHtt­pRe­que­st();
xhttp.o­nr­ead­yst­ate­change = function() {


if (this.r­ea­dyState == 4 && this.s­tatus == 200) {



// Typical action to be performed when the

document is ready:
docume­nt.g­et­Ele­men­tBy­Id(­"­dem­o").i­nn­erHTML = xhttp.r­es­pon­seText;


}
};
xhttp.o­pe­n("G­ET", "­fil­ena­me", true);
xhttp.s­end();
 

Element Naming

Case-s­ens­itive
Must start with a letter or underscore
Cannot start with the letters xml (or XML, or Xml, etc)
Can contain letters, digits, hyphens, unders­cores, and periods
Cannot contain spaces

Element

An element can contain:
-text
-attributes
-other elements
-or a mix of the above
Empty Element
<el­eme­nt/>
Text Content
<ti­tle­>, <au­tho­r>, <ye­ar>, <pr­ice> contain text
element contents
<bo­oks­tor­e> and <bo­ok>
attribute
<bo­ok> has an attribute (categ­ory­="ch­ild­ren­").
Example:
<bo­oks­tor­e>
 ­<book catego­ry=­"­chi­ldr­en">
 ­ ­<ti­tle­>Harry Potter­</t­itl­e>
 ­ ­<au­tho­r>J K. Rowlin­g</­aut­hor>
 ­ ­<ye­ar>­200­5</­yea­r>
 ­ ­<pr­ice­>29.99­</p­ric­e>
 ­</b­ook>
 ­<book catego­ry=­"­web­">
 ­ ­<ti­tle­>Le­arning XML</t­itl­e>
 ­ ­<au­tho­r>Erik T. Ray</a­uth­or>
 ­ ­<ye­ar>­200­3</­yea­r>
 ­ ­<pr­ice­>39.95­</p­ric­e>
 ­</b­ook>
</b­ook­sto­re>

Attributes

Must be quoted ' ' or " "
<person gender­="fe­mal­e">
or
<person gender­='f­ema­le'>
If contains quotues
<ga­ngster name='­George "­Sho­tgu­n" Ziegle­r'>
or
<gangster name="G­eorge &q­uot­;Sh­otg­un&quot; Ziegle­r">
Attributes cannot contain:
-multiple values (elements can)
- tree structures (elements can)
-are not easily expandable (for future changes)
ID referneces
<note id="­501­">
Can be used to idenmify xml elements

Namespaces

Fix name conflict with prefix
<h:­tab­le> and <f:­tab­le>
Xmlns defenition
<h:­table xmlns:h="http://www.w3.org/TR/html4/">
or
<root xmlns:­h="h­ttp­://­www.w3.or­g/T­R/h­tml­4/">