XML - eXtensible: you can make up your own tags
Foundation of several technologies, XHTML, RSS/ATOM, AJAX, APIs
Structures and describes information
Intended to be used a an Internet technologies
XML can help different apps communicate.
XPath - navigates data in XML - XSLT - style transformations - XQuery queries XML - XPointer links between XML docs
Jeremy 555-1212 555-1212tags describe the data, the data is between the tags
XML is not good for large datasets - XML is not as good as JSON in javascript - Doesn't represent binary data very well - Note easy to read
Types:
- Document declarations - (optional, but recommended)
- Element and attributes - (tags), need valid names, cannot use "xml" in string,
- Comments - embed information for reader
- Character data - dta not parsed , can be used to embed scripts
- Processing Instructions -
- Entity references - shorten XML documents, character entities < or &
Syntax:
- must have a single root tag
- must be well-formed
- empty tags must be closed with /> (like an img tag)
- attribute tags cannot be minimized, values must be in quotes
- tags need to be properly nested
Valid xml:
- DTDs, and XML Schema
Namespaces:
- keep tag names from coliding.
To associate XML with CSS: <?xml-stylesheet type="text/css" href="FirstXMLFile.css" ?>
nodeName -> name of node
nodeType -> type (element, tag, etc.)
nodeValue -> values
attributes -> elements only, an array of attributes and values
parentNode -> gives you parent of node, null if oyu're at root
childNodes -> array of child notes, array#length == 0 if there are no nodes
firstChild lastChild -> first and last child node.
previousSibling nextSibling -> self-explanatory.
Functions:
appendChild()
removeChild()
insertBefore()
replaceChild()
documentElement -> references root doc element
createElement() ->
createTextNode() ->
createComment()
createCDATASection()
getElementsByTagName()
getElementsById()
getAttribute()
setAttribute()
removeAttribute()
/html/head/title
/html/body/p[1]
(Xpath is 1-based)
Context node - where xpath query starts
Axis is relation between context and selected node
Predicates are further refinements of XPath
/
- root
/rootTag
- selects
'//tagName
- finds all tagName(s)
/doc/chapter[5]
selects fifth chapter in doc
/body/p[last()]
selects last p in body
/body/p[@class='a']
se;ects p with class of a in body
//p[@class and @style]
all p in doc with class and style
Creating a stylesheet, use: <xsl:stylesheet >
rfoot tag
contain <xsl:template>
tags which are matched to XML tags in the source data.
template contents replace source data
components:
<xsl:stylesheet>
- defines document as XSL
<xsl:template match="myXPath">
- template matches data xpath
<xsl:value-of select="xpath">
- xsl can be called on data like a function
<xsl:attribute>
<xsl:text>
<xsl:foreach select="xpath">
<xsl:if test="condition">
<xsl:choose>
<xsl:when>
<xsl:otherwise>
<xsl:sort select="">
To associated an XML doc with XSLT:
<?xml-stylesheet type="text/xsl" href="path_to/myXml.xml">
declared using <xsd:element>
xsd:string
xsd:boolean
xsd:integer
xsd:decimal
xsd:positiveInteg
xsd:negativeInteg
xsd:anyUri
xsd:date
xsd:time
xsd:dateTime
xsd:gMonth (gregorigan month) / etc... /
Example: <xsd:element name="MyElement" type="xsd:string">
is restricted to being a string