Changeset 4437:6f3d4e845072 in livinglogic.python.xist for src/ll/xist/scripts/dtd2xsc.py

Show
Ignore:
Timestamp:
03/25/11 15:57:19 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix typos in script documentation. Add examples. Bump version number.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/scripts/dtd2xsc.py

    r4435 r4437  
    1111 
    1212""" 
     13Purpose 
     14------- 
     15 
    1316``dtd2xsc`` is a script that helps create XIST namespace modules from DTDs. 
    1417It reads one or more DTDs and outputs a skeleton namespace module. 
    1518 
     19 
     20Options 
     21------- 
     22 
    1623``dtd2xsc`` supports the following options: 
    1724 
    1825    ``urls`` 
    19         Zerone or more URLs (or filenames) of DTDs to be parsed. If no URL is 
     26        Zero or more URLs (or filenames) of DTDs to be parsed. If no URL is 
    2027        given stdin will be read. 
    2128 
     
    5562 
    5663    .. _xmlproc: http://www.garshol.priv.no/download/software/xmlproc/ 
     64 
     65 
     66Example 
     67------- 
     68 
     69Suppose we have the following DTD file (named ``foo.dtd``):: 
     70 
     71    <?xml version="1.0" encoding="ISO-8859-1"?> 
     72    <!ELEMENT persons (person*)> 
     73    <!ELEMENT person (firstname?, lastname?)> 
     74    <!ATTLIST person id CDATA #REQUIRED> 
     75    <!ELEMENT firstname (#PCDATA)> 
     76    <!ELEMENT lastname (#PCDATA)> 
     77 
     78Then we can generate a skeleton XIST namespace from it with the following command:: 
     79 
     80    dtd2xsc ~/gurk.dtd -xhttp://xmlns.example.org/ -mfullall 
     81 
     82The output will be:: 
     83 
     84    # -*- coding: ascii -*- 
     85 
     86 
     87    from ll.xist import xsc, sims 
     88 
     89 
     90    xmlns = 'http://xmlns.example.org/' 
     91 
     92 
     93    class firstname(xsc.Element): xmlns = xmlns 
     94 
     95 
     96    class lastname(xsc.Element): xmlns = xmlns 
     97 
     98 
     99    class person(xsc.Element): 
     100        xmlns = xmlns 
     101        class Attrs(xsc.Element.Attrs): 
     102            class id(xsc.TextAttr): required = True 
     103 
     104 
     105    class persons(xsc.Element): xmlns = xmlns 
     106 
     107 
     108    person.model = sims.Elements(lastname, firstname) 
     109    persons.model = sims.Elements(person) 
     110    firstname.model = sims.NoElements() 
     111    lastname.model = sims.NoElements() 
    57112""" 
    58113 
     
    211266    p.add_argument("-x", "--xmlns", dest="defaultxmlns", metavar="NAME", help="the namespace name for this module") 
    212267    p.add_argument("-s", "--shareattrs", dest="shareattrs", help="Should identical attributes be shared among elements? (default: %(default)s)", choices=("none", "dupes", "all"), default="dupes") 
    213     p.add_argument("-m", "--model", dest="model", default="once", help="Add sims information to the namespace (default: %(default)s)", choices=("no", "simple", "fullall", "fullonce")) 
     268    p.add_argument("-m", "--model", dest="model", default="fullonce", help="Add sims information to the namespace (default: %(default)s)", choices=("no", "simple", "fullall", "fullonce")) 
    214269    p.add_argument("-d", "--defaults", dest="defaults", help="Output default values for attributes? (default: %(default)s)", action=misc.FlagAction, default=False) 
    215270    p.add_argument(      "--duplicates", dest="duplicates", help="How to handle duplicate elements from multiple DTDs (default: %(default)s)", choices=("reject", "allow", "merge"), default="reject")