Project | WXT | Basics | Download | Documentation | Samples

PI: importxml

The purpose of an importxml PI is to produce an XML-fragment and replace the PI with this fragment.

WXT may attempt to do a simple tiding with jsoup [16] if parsing of the XML-material fails. Note however that even if the tidy job is successfull the result may no be exactly as you expect.

<?_wxt importxml xpath="" location="" transformation=""?>

The parameters are:

xpath (mandatory) Any xpath expression that identifies a nodeset that will be treated like a XML-fragment.
location mandatory, but optional in templates The URI of the file we want to import from. WXT will if necessary attempt to tidy the source.
In templates the location parameter is usually skipped. In this case all content files owned by the module in the script are searched for appropriate content unless you reduce the search with parameter id, see below.
transformation (optional) A transformation identifier (see: Transformation ). This transformation may have parameters: T(name='ole' address='halden'). This transformation is applied before we attempt to extract with xpath.
encoding (optional) You can spesify expected encoding if you expect the import to be without XML-header stating the encoding. Default encoding is UTF-8 if not set otherwise in script (option: default-encoding).
id (optional) An id that match the id of the actual xmlimport in script. Has only meaning when this element has no location. One reason to use an id is processing time if you have many contentfiles to a module. Another reason may be that you have similar structures in different contentfiles and you want to be selective.

Examples:

<?_wxt importxml xpath="//h1"?>
<?_wxt importxml xpath="//div[@class='main']/*"?>
<?_wxt importxml 
        location="http://www.ia.hiof.no/~borres/ml/index.shtml" 
        xpath="//div[@class='main']/*"?>
<?_wxt importxml uri="../quotes/q.xml" 
        xpath="//p[@class='quot']/*"?>
<?_wxt importxml xpath="//div[@id='main']" 
        location="b.xml" 
        transformation="myT(para='hello',parb='goodbye')"?>