Reference

This section gives an overview on all TypoScript properties of the XPATH content object. You can also have a look into the README.txt file within the doc folder to get a configuration example.

Property

source

Data type

string/stdWrap

Description

This fetches the XML data from a source. Can be a XML string, a field in the database, a file (path or via TypoScript FILE cObject) or an external resource.

Example (field):

page.10 = XPATH
page.10 {
   source.data = page : my_xml_field
   [...]
}

Fetches the XML from the field ‘my_xml_field’ of the current page record.

Example (stdWrap / FILE):

page.10 = XPATH
page.10 {
   source.cObject = FILE
   source.cObject.file = fileadmin/myfile.xml
   [...]
}

This fetches the XML from a file included by TypoScript’s FILE content object. Important: Due to FILE’s internal settings, the data can’t be larger than 1024kb. See TSref.

Example (external):

page.10 = XPATH
page.10 {
   source = http://news.typo3.org/rss.xml
   [...]
}

This draws the XML from an external source. It can be an URL like above or an external file resource of any size.

Property

registerNamespace

Data type

string/+ subproperties

Description

Registers a namespace for use with the XPATH expression. Syntax is prefix|namespace . The namespace must match a namespace in the source, otherwise the XPATH query will return false.

Example:

page.10 = XPATH
page.10 {
   registerNamespace = c|http://example.org/chapter-title
   expression = //c:title
   [...]
}

It’s possible to extract the namespaces of the XML source with the following subproperties:

Subproperties:

.getFromSource [boolean]

.getFromSource.debug [boolean]

.getFromSource.listNum [integer]

getFromSource will retrieve the namespaces from the source rather than taking the string given in the parent property. With debug it’s possible to see what namespaces are returned. listNum is a TypoScript listNum with which you can select any of the (possibly several) namespaces returned from the XML source.

Property

expression

Data type

string/stdWrap

Description

XPATH expression.

Example:

page.10 = XPATH
page.10 {
   expression = //item
   [...]
}

Gets all <item> nodes from the XML source.

Example (with stdWrap):

page.10 = XPATH
page.10 {
   expression = //item[{register:count}]
   expression.insertData = 1
   [...]
}

Fetches the item by the number found in the TypoScript register.

Property

return

Data type

keyword/stdWrap

Description

This sets the return value for the XPATH query. Can be one of the following keywords:

count

Returns the number of the nodes/attributes matched by the XPATH expression

boolean

Returns true or false depending if the XPATH expression matched any nodes/attributes

xml

Returns all matched nodes and their child nodes as XML. Should be used in conjunction with .resultObj or .directReturn

array

Converts and returns all nodes matched by the XPATH expression in an array structure. Should be used in conjunction with .resultObj or .directReturn

json

Converts and returns all nodes matched by the XPATH expression in json format. Should be used in conjunction with .resultObj or .directReturn

string

Converts and returns all items matched by the XPATH expression as strings (atomic node values). Should be used in conjunction with .resultObj or .directReturn

Example:

page.10 = XPATH
page.10 {
   source.data = page : my_xml_field
   expression = //title
   return = string
   [...]
}

Default

string

Property

resultObj

Data type

see TSref split

Description

As the name says, the result object contains the result of the XPATH query (i.e. all matched nodes, attributes, etc). The resultObj works similar to the well known TypoScript split property. This makes the handling of the returned items very flexible. You can use option split, stdWrap, parseFunc and all the other nice stuff from TSref :)

Example:

page.10 = XPATH
page.10 {

   source.data = page : my_xml_field
   expression = //title
   return = string

   resultObj {
      cObjNum = 1 || 2

      1.current = 1
      1.wrap = <h1 style="color:red">|</h1>

      2.current = 1
      2.wrap = <h1 style="color:green">|</h1>
   }
}

Property

implodeResult

Data type

boolean/+token

Description

Instead of processing the XPATH result set with resultObj, this setting directly returns the whole set imploded around a token. This way you can split or explode the result yourself and do further processing, depending on your usecase. Can be useful for passing on result arrays to a FLUIDTEMPLATE for example.

token (string/stdWrap)

Sets the token around which the result set is imploded.

Default

###COBJ_XPATH###

Property

stdWrap

Data type

stdWrap

Description

stdWrap properties for the XPATH cObject

Example:

page.10 = XPATH
page.10 {

   [...]

   stdWrap {
      outerWrap = <code>|</code>
      htmlSpecialChars = 1
   }
}