Link: start
Link: parent
Link: First page in set (first)
Link: Previous page (previous)
Link: Next page (next)
Link: Last page in set (last)
Link: A plain text version of this page (alternate)
Link: The XIST source of this page (alternate)
XIST miscellaneous
==================
URLs, pretty printing, image sizes, embedding Python code
=========================================================
Home > Python software > ll.xist > Miscellaneous Text · XIST
Python softwarelist of projects
* ll.xistAn extensible XML/HTML generator
* ExamplesParsing/creating/modifying XML; Traversing XML
trees
* HowtoExplains parsing/generating XML files, XML
transformations via XIST classes and other basic
concepts.
* SearchingHow to iterate through XIST trees
* TransformationHow to transform XIST trees
* Advanced topicsPool chaining, converter contexts,
validation
* MiscellaneousExplains various odds and ends of XIST
* xscXIST core classes
* nsPackage containing namespace modules
* parseParsing XML
* presentScreen output of XML trees
* simsSimple schema validation
* xfindTree iteration and filtering
* cssCSS related functions
* scriptsScripts for text conversion and creating XIST
namespaces
* HistoryChangeLog for XIST
* InstallationHow to install and configure XIST
* MigrationHow to update your code to new versions of XIST
* Mailing listsHow to subscribe to the XIST mailing lists
* ll.ul4cA templating language
* ll.urlRFC 2396 compliant URLs
* ll.makeObject oriented make replacement
* ll.daemonForking daemon processes
* ll.sisyphusWriting cron jobs with Python
* ll.colorRGB color values and color model conversion
* ll.miscMisc utility functions and classes
* ll.orasqlUtilities for cx_Oracle
* ll.nightshadeServe the output of Oracle functions/procedures
with CherryPy
* ll.scriptsScripts for UL4 template rendering and URL handling
* AploraLogging Apache HTTP requests to an Oracle database
* PycocoPython code coverage
* DownloadLinks to Windows and Linux, source and binary
distributions
* Source codeAccess to the Mercurial repositories
URLs
====
For URL handling XIST uses the module ll.url. Refer to its
documentation for the basic functionality (especially regarding
the methods __div__ and relative).
When XIST parses an XML resource it uses a so called "base" URL.
This base URL can be passed to all parsing functions. If it isn't
specified it defaults to the URL of the resource being parsed.
This base URL will be prepended to all URLs that are read during
parsing:
>>> from ll.xist import parse
>>> from ll.xist.ns import html
>>> node = parse.parsestring('
', base="root:spam/index.html")
>>> print node.bytes()
For publishing a base URL can be specified too. URLs will be
published relative to this base URL with the exception of relative
URLs in the tree. This means:
* When you have a relative URL (e.g. #top) generated by a
convert call, this URL will stay the same when publishing.
* Base URLs for parsing should never be relative: Relative base
URLs will be prepended to all relative URLs in the file, but
this will not be reverted for publishing. In most cases the
base URL should be a root URL when you parse local files.
* When you parse remote web pages you can either omit the base
argument, so it will default to the URL being parsing, so that
links, images, etc. on the page will still point back to their
original location, or you might want to use the empty URL
URL() as the base, so you'll get all URLs in the page as they
are.
* When XIST is used as a compiler for static pages, you're going
to read source XML files, do a conversion and write the result
to a new target file. In this case you should probably use the
URL of the target file for both parsing and publishing. Let's
assume we have an URL #top in the source file. When we use the
"real" file names for parsing and publishing like this:
node = parse.parsefile("spam.htmlxsc", base="root:spam.htmlxsc")
node = node.conv()
node.write(open("spam.html", "wb"), base="root:spam.html")
the following will happen: The URL #top will be parsed as
root:spam.htmlxsc#top. After conversion this will be written
to spam.html relative to the URL root:spam.html, which results
in spam.html#top, which works, but is not what you want.
When you use root:spam.html both for parsing and publishing,
#top will be written to the target file as expected.
Pretty printing XML
===================
The method pretty can be used for pretty printing XML. It returns
a new version of the node, with additional white space between the
elements:
from ll.xist.ns import html
node = html.html(
· html.head(
· · html.title(u"foo"),
· ),
· html.body(
· · html.div(
· · · html.h1(u"The ", html.em(u"foo"), u" page!"),
· · · html.p(u"Welcome to the ", html.em(u"foo"), u" page."),
· · ),
· ),
)
print node.pretty().bytes()
This will print:
·
Welcome to the foo page.
· ·