Purpose
xml2xsc
is a script that generates an XIST namespace module from one or more
XML files. xml2xsc
will output an XIST element class for each element it
encounters in any of the XML files. The attributes and model information
xml2xsc
assigns to an element will be collected from each occurence of the
element in the XML files, so the XML files should cover as many different cases
as possible.
Options
xml2xsc
supports the following options:
urls
Zero or more URLs (or filenames) of XML files to be parsed. If no URL is given stdin will be read.
-p
,--parser
(etree
orlxml
)Which XML parser should be used from parsing the XML files? (
etree
is the default,lxml
requires that lxml is installed)-s
,--shareattrs
(none
,dupes
,all
)Should attributes be shared among the elements?
none
means that each element will have its own standaloneAttrs
class directly derived fromll.xist.Elements.Attrs
. Fordupes
each attribute that is used by more than one element will be moved into its ownAttrs
class. Forall
this will be done for all attributes.-m
,--model
(no
,simple
,fullall
,fullonce
)Add model information to the namespace.
no
doesn't add any model information.simple
only addsmodel = False
ormodel = True
(i.e. only the information whether the element must be empty or not).fullall
adds all.xist.sims
model object to each element class.fullonce
adds full model information to, but reuses model objects for elements which have the same model.-x
,--defaultxmlns
The default namespace name. All elements that don't belong to any namespace will be assigned to this namespace.
Example
Suppose we have the following XML file (named foo.xml
):
<x a="0"><x b="1"/><y/></x>
Then we can generate a skeleton XIST namespace from it with the following command:
xml2xsc foo.xml -xhttp://xmlns.example.org/ -mfullonce
The output will be:
# -*- coding: ascii -*- from ll.xist import xsc, sims xmlns = 'http://xmlns.example.org/' class x(xsc.Element): xmlns = xmlns class Attrs(xsc.Element.Attrs): class a(xsc.TextAttr): pass class b(xsc.TextAttr): pass class y(xsc.Element): xmlns = xmlns x.model = sims.Elements(y, x) y.model = sims.Empty()