Monthly Archives: December 2008

Embedding Base64 images in HTML

It is really possible to embed a base64 encoded image inside an <img /> tag in html
The following links have more information on it:


http://www.greywyvern.com/code/php/binary2base64

http://danielmclaren.net/2008/03/embedding-base64-image-data-into-a-webpage
http://dean.edwards.name/weblog/2005/06/base64-ie/

DTD Cheat Sheet


This is a cheat sheet for the DTDlanguage. It is a follow up to theXML Cheat Sheet and summarizesthis DTD Tutorial. There is also an XML Schema Cheat Sheet.

For reference this is the XML Specification (which also documentsDTD) and the version annotated by Tim Gray.

  • A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.
  • A DTD can be internally defined e.g.
<!DOCTYPE root-element [
element-declarations
]>

or externally defined e.g.


<!DOCTYPE root-element SYSTEM “filename.dtd”>

where the element-declarations are in filename.dtd

  • A simple example of DTD element-declarations
 <!ELEMENT note (to,from)>
<!ELEMENT to      (#PCDATA)>
<!ELEMENT from    (#PCDATA)>

This says that note contains 2 child elements and to and from are of type #PCDATA .

  • A DTD for an XML document may contain the following building blocks
  • elements
  • attributes
  • entities (e.g. character entities)
  • PCDATA (parsed character data parsed for entities and markup)
  • CDATA (character data that is not parsed)

DTD Elements

  • An element is defined as
<!ELEMENT element-name category>

or

<!ELEMENT element-name (element-content)>
  • category can be either EMPTY or ANY
  • element-content can be any combination of #PCDATA or child elements
  • child_element+ – one or more occurrences
  • child_element* – zero or more occurrences
  • child_element? – zero or one occurrences
  • (a|b) – Either a or b (can be #PCDATA)
  • a,b – a and then b in that order

DTD Attributes

  • An attribute specified in a DTD takes the form
<!ATTLIST element-name
attribute-name attribute-type default-value
attribute-name2 attribute-type2 default-value2
   … >

for example:

<!ATTLIST payment
 currency CDATA “US Dollars”
 amount CDATA #REQUIRED
 form (Cash|Cheque) “Cheque”>
  • attribute-type can be one of the following
  • CDATA – character data
  • (en1|en2|..) – one from an enumerated list
  • ID – a unique id
  • IDREF – the id of another element
  • IDREFS – a list of other ids
  • NMTOKEN – a valid XML name
  • NMTOKENS – a list of valid XML names
  • ENTITY – an entity
  • ENTITIES – a list of entities
  • NOTATION – a name of a notation
  • xml: – a predefined xml value
  • default-value can be one of the following
    • value – the default value of the attribute
    • #REQUIRED – attribute is required but with no default
    • #IMPLIED – attribute is optional and with no default
    • #FIXED value – the attribute value is fixed

    DTD Entities

    • Entities are variables used to define shortcuts to standard text or special characters.
    • Entities are declared in DTDs and can be declared internal e.g.
    <!ENTITY writer “Donald Duck.”>

    or external e.g.

    <!ENTITY writer SYSTEM “http://a.com/entities.dtd”>
    • Entity references are references to entities and may be used inXML documents.
    • An entity reference has three parts: an ampersand (&), an entity name, and a semicolon (;). e.g.

    XML Course 11

    Some DTD’s for the startup that was missed.


    http://www.cafeconleche.org/slides/javapolis/effectivexml/index.html

     
    http://www.cafeconleche.org/slides/javapolis/effectivexml/16.html
    http://www.cafeconleche.org/slides/javapolis/effectivexml/35.html
    http://www.cafeconleche.org/slides/javapolis/effectivexml/41.html
    http://www.cafeconleche.org/slides/javapolis/effectivexml/43.html
    http://www.cafeconleche.org/slides/javapolis/effectivexml/59.html
    http://www.cafeconleche.org/slides/javapolis/effectivexml/73.html
     
    http://www.jroller.com/evans/entry/missing_xslt_dtd_and_xml
    http://www.jroller.com/evans/entry/missing_xslt_dtd_and_xml1

    Controlling break space and white space in XSLT output



    <xsl:output method=”xml” indent=”yes”/>

    Saying indent=”yes” in xsl:output allows the processor to indent the output any way it chooses. If you don’t want that, don’t specify indent=”yes”; you will then get no extra whitespace in the output unless you create it explicitly using <xsl:value-of> or <xsl:text>.

    If you want more intelligent formatting, you can use Saxon in schema-aware mode, validating the output against a schema. It will then avoid applying indentation to elements that are defined in the schema to have a mixed content model, which seems to be the effect you are looking for here.

    ———————————————–

    <xsl:variable name=”newline”>
    <xsl:text>
    </xsl:text>
    </xsl:variable>


    usage:
    <xsl:value-of select=”$newline”> <!– line break in output file –>

    ———————————————–
    http://www.ibm.com/developerworks/xml/library/x-tipwhitesp.html


    <xsl:template match=”/”>
    <faqoutput><xsl:text>
      </xsl:text><info xml:space=”preserve”>
         <title xml:space=”default”>
           <xsl:value-of select=”faqs/question/questiontitle”/>
         </title>
      </info>
      <xsl:apply-templates/>
    </faqoutput>
    </xsl:template>

    ————————————————
    <xsl:text> </xsl:text>

    ————————————————

    Use <xsl:text></xsl:text> to contain literal white space;
    you can even do something clever like <xsl:text>
    </xsl:text> to send just a newline, or <xsl:text> </xsl:text>
    to send five blanks.

    And if you use <xsl:if test=…>, you can send your literal
    output based on an arbitrary condition.