Cheatography
https://cheatography.com
xml cheat sheet with syntax etc
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Syntax
<root> <child> <subchild>.....</subchild> </child> </root> |
<note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> |
Commenting
<!-- This is a comment --> |
Prolog
<?xml version="1.0" encoding="UTF-8"?> |
UTF-8 is the default character encoding for XML documents. |
The XML prolog is optional. |
Entity References
< |
< |
> |
> |
& |
& |
' |
' |
" |
" |
HttpRequest
The first line in the example above creates an XMLHttpRequest object: |
var xhttp = new XMLHttpRequest(); |
The onreadystatechange property specifies a function to be executed every time the status of the XMLHttpRequest object changes: |
xhttp.onreadystatechange = function() |
When readyState property is 4 and the status property is 200, the response is ready: |
if (this.readyState == 4 && this.status == 200) |
The responseText property returns the server response as a text string.The text string can be used to update a web page: |
document.getElementById("demo").innerHTML = xhttp.responseText; |
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the
document is ready:
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "filename", true);
xhttp.send();
|
|
Element Naming
Case-sensitive |
Must start with a letter or underscore |
Cannot start with the letters xml (or XML, or Xml, etc) |
Can contain letters, digits, hyphens, underscores, and periods |
Cannot contain spaces |
Element
An element can contain: |
-text -attributes -other elements -or a mix of the above |
Empty Element |
<element/> |
Text Content |
<title>, <author>, <year>, <price> contain text |
element contents |
<bookstore> and <book> |
attribute |
<book> has an attribute (category="children"). |
Example:
<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Attributes
Must be quoted ' ' or " " |
<person gender="female"> or <person gender='female'> |
If contains quotues |
<gangster name='George "Shotgun" Ziegler'> or <gangster name="George "Shotgun" Ziegler"> |
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:table> and <f:table> |
Xmlns defenition |
<h:table xmlns:h="http://www.w3.org/TR/html4/"> or <root xmlns:h="http://www.w3.org/TR/html4/"> |
|