DEPRECATION WARNING
This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.
EXT: [drecomm] Page tree to XML¶
Author: | Kasper Skårhøj |
---|---|
Created: | 2002-11-01T00:32:00 |
Changed: | 2006-05-16T13:53:19 |
Author: | Bas Hoonhout |
Email: | bas.hoonhout@drecomm.nl |
Info 3: | |
Info 4: |
EXT: [drecomm] Page tree to XML¶
Extension Key: dre_pt2xml
Copyright 2005-2006, Bas Hoonhout, <bas.hoonhout@drecomm.nl>
This document is published under the Open Content License
available from http://www.opencontent.org/opl.shtml
The content of this document is related to TYPO3
- a GNU/GPL CMS/Framework available from www.typo3.com
Table of Contents¶
EXT: [drecomm] Page tree to XML 1
Introduction 1
What does it do? 1
Screenshots 1
Configuration 2
Reference 5
Known problems 6
To-Do list 6
Changelog 6
Introduction¶
What does it do?¶
Installing the extension enables users to display a certain part of the pagetree of TYPO3 in XML. For example, the generated XML could be used as input for a Flash application that generates menu's.
When the extension is just installed, requesting a certain page with &type=555 in the querystring will result in a XML structure of the pages beneath. The layout of the XML structure can be fully adapted to the needs of the end-user. See the Configuration part of this document.
Screenshots¶
The layout of the generated XML is fully determined by the TypoScript configuration. A default configuration is added to all pages in the TYPO3 page tree. This default configuration can easily be modified in order to suit the needs of the end-user:
The default configuration will result in the following XML structure:
Configuration¶
It's possible to configure the plugin fully using TypoScript. Some default lines of TypoScript code will be added after very single template. These lines provide the default behaviour of the plugin, which can be modified, of course. The default behaviour is that when a page is requested with &type=555 in the querystring, a XML structure is generated based on the pages beneath. This XML structure will probably be useless for most users and is there only as example and startingpoint.
Below is a slightly modified version of these default lines of TypoScript displayed. Using this code, all different configuration options will be explained.
dre_pt2xml >
dre_pt2xml = PAGE
dre_pt2xml {
typeNum = 555
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:text/xml
admPanel = 0
}
10 = USER
10 {
includeLibs.dre_pt2xml = EXT:dre_pt2xml/pi1/class.tx_drept2xml_pi1.php
userFunc = tx_drept2xml_pi1->main
parameters {
startPID = 8
extraHeaders = <?xml version="1.0" encoding="utf-8"?>
rootTagName = rootTag
rootTagAttributes = attribute_1="some_value" attribute_2="some_other_value"
linkPrefix = http://www.some-prefixed-url.com/
actLikeMenu = 1
10 = LEVEL
10 {
tagName = firstLevel
header = ATTRIBUTE
header {
name = header
field = title
}
}
15 = TAG
15 {
tagName = extraTag
beforeSiblings = 1
condition = title!=FirstTitle AND title!=SecondTitle
some_cdata = CDATA
some_cdata.value = some_value
some_attribute = ATTRIBUTE
some_attribute {
name = some_attribute_name
value = some_value
}
}
20 = LEVEL
20 {
tagName = secondLevel
cdata = CDATA
cdata.field = title
color = ATTRIBUTE
color {
name = color
value = 0000ff
}
link = ATTRIBUTE
link {
name = link
link = 1
typeNum = 6
ampercentNotEncoded = 0
}
}
}
}
}
The code above will be repeated and explained, step by step. The code uses almost every configuration option that's possible. Of course, the default TypoScript options like conditions and copying objects can be used as well. For example, this default object will always (!) be available and can be copied and modified easily.
First, the code creates a PAGE object with a typeNum 555. This is an arbitary typeNum, which could be every other typeNum, even zero.
dre_pt2xml >
dre_pt2xml = PAGE
dre_pt2xml {
typeNum = 555
...
In the next part a number of configuration options for the just created page will be set. First of all, all headers are removed, then the Content-type is set to text/xml and then the admin panel is disabled. This is all necessary to guarantee a clean XML structure without any HTML code in it.
...
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:text/xml
admPanel = 0
}
...
In the PAGE object, a USER object is created. Then, a library is included. This library contains the PHP class that provides the conversion to XML. Then, the main function of this class is called.
...
10 = USER
10 {
includeLibs.dre_pt2xml = EXT:dre_pt2xml/pi1/class.tx_drept2xml_pi1.php
userFunc = tx_drept2xml_pi1->main
...
The plugin is configured using a certain objects and attributes collected in the attribute parameters . The attributes for general configuration are shown below. All these attributes are optional.
startPID defines where the plugin has to start searching in the Typo3 page tree. If startPID is not set, the current page is used. extraHeaders can be used to add extra code above the genereated XML structure. This could be version or encoding information, like in the example. Furthermore, the generated XML structure is wrapped in a XML root tag, if provided. The name of the XML root tag is set with the attribute rootTagName and it's attributes are set with the attribute rootTagAttributes . Every link, generated by the plugin, will be preceded by the string defined with the attribute linkPrefix (generating links will be explained later). The last attribute is actLikeMenu . By default, this attribute is set to 1 in order to return only the pages in the page tree that are valid for menu's. In other words: if this attribute is set to one, only pages that are not 'Not in menu' and 'System' pages are returned, otherwise all pages (that are not hidden) are returned.
...
parameters {
startPID = 8
extraHeaders = <?xml version="1.0" encoding="utf-8"?>
rootTagName = rootTag
rootTagAttributes = attribute_1="some_value" attribute_2="some_other_value"
linkPrefix = http://www.some-prefixed-url.com/
actLikeMenu = 1
...
Until now, the configuration will result in an empty XML structure, although there would be some headers and browsers would reconize the document as XML. To get a XML structure, levels has to be defined. The number of levels corresponds with the depth in which the plugin has to enter the page tree, seen from it's startingpoint. So, three levels corresponds with a maximum of three 'generations' of pages in the generated XML structure.
A level can be defined by creating a LEVEL object. A LEVEL object always needs the attribute tagName . The value of this attribute defines the name of the XML tag representing this level of pages in the generated XML structure. A LEVEL object can also contain ATTRIBUTE objects. Every ATTRIBUTE object will result in a XML attribute in the corresponding XML tag. A ATTRIBUTE object has two attributes. The attribute name contains the name of the generated XML attribute. The value of this XML attribute can be set in three different ways. When the attribute value is used, the value of this attribute is directly copied to the XML attribute. When the attribute field is used, the value of that field in the pages record of the corresponding page is copied to the XML attribute. Furthermore, there is the attribute link . When this attribute is used, a link (index.php?id= uid ) to the corresponding page is used as value for the XML attribute. All links are preceded by the string defined in the attribute linkPrefix . The link can be extended with a type variable (index.php?id= uid &type= typeNum ) by adding a attribute typeNum to the ATTRIBUTE object. Since the &-sign is encoded like '&' by default, but this won't work when feeding the resulted XML to, for example, a Macromedia Flash application, it is possible to keep plain &-signs in the resulted XML by setting the attribute ampercentNotEncoded to 1. This might, however, result in an error when parsing the XML through Microsoft Internet Explorer, Mozilla Firefox or any other XML parsing application.
Next to ATTRIBUTE objects, a LEVEL object can also contain CDATA objects. A CDATA object is almost the same as an ATTRIBUTE object, except that there is no name attribute and it will not result in an other XML attribute, but the result is placed between the opening and closing XML tags.
LEVEL objects kan also contain the attribute condition . This will be explained in the next paragraph for the TAG object, but works the same way for the LEVEL object.
...
10 = LEVEL
10 {
tagName = firstLevel
header = ATTRIBUTE
header {
name = header
field = title
}
}
...
20 = LEVEL
20 {
tagName = secondLevel
cdata = CDATA
cdata.field = title
color = ATTRIBUTE
color {
name = color
value = 0000ff
}
link = ATTRIBUTE
link {
name = link
link = 1
typeNum = 6
ampercentNotEncoded = 0
}
}
...
In the previous paragraph a part form the example code was left out in comparison to the original. In this part another object is defined: the TAG object. The TAG object results at the level of the last LEVEL object in a custom XML tag with custom XML attributes. Like with LEVEL objects, a TAG object can also contain CDATA and ATTRIBUTE objects, which will work in exactly the same way.
In the example above of LEVEL objects, the condition attribute is not used like in the example below. With this attribute, next to default condition methods of TypoScript, it's possible to exclude certain pages fro the XML structure. Only the pages for which the expression in the condition attribute will result in a true value will be used. An expression contains a serie of fieldname/value pairs glued together with a ' AND ' or ' OR ' operator. The fieldnames and values itself are glued together with a '==' or '!=' operator. The fieldname is a fieldname from the pages table and the value is a static value.
The attribute beforeSiblings is only available for the TAG object and decides whether the XML tag is placed before or after it's corresponding LEVEL object in the generated XML structure.
...
15 = TAG
15 {
tagName = extraTag
beforeSiblings = 1
condition = title!=FirstTitle AND title!=SecondTitle
some_cdata = CDATA
some_cdata.value = some_value
some_attribute = ATTRIBUTE
some_attribute {
name = some_attribute_name
value = some_value
}
}
...
Depending on the exact page tree, the configuration above could result in the XML structure below:
<?xml version="1.0" encoding="utf-8"?>
<rootTag attribute_1="some_value" attribute_2="some_other_value">
<extraTag some_attribute_name="some_value">
some_value
</extraTag>
<firstLevel header="Waves">
<secondLevel color="0000ff" link="http://www.some-prefixed-url.com/
index.php?id=21">Wave 1</secondLevel>
<secondLevel color="0000ff" link="http://www.some-prefixed-url.com/
index.php?id=20">Wave 2</secondLevel>
<secondLevel color="0000ff" link="http://www.some-prefixed-url.com/
index.php?id=19">Wave 3</secondLevel>
<secondLevel color="0000ff" link="http://www.some-prefixed-url.com/
index.php?id=18">Wave 4</secondLevel>
</firstLevel>
</rootTag>
Reference¶
USER object parameters reference:
startPID¶
Property
startPID
Data type
integer
Description
startPID defines where the plugin has to start searching in the Typo3 page tree. If startPID is not set, the current page is used.
Default
PID of requested page
extraHeaders¶
Property
extraHeaders
Data type
string
Description
extraHeaders can be used to add extra code above the genereated XML structure.
Default
rootTagName¶
Property
rootTagName
Data type
string
Description
The value of rootTagName defines the name of the tag in which the whole XML structure is wrapped.
Default
rootTagAttributes¶
Property
rootTagAttributes
Data type
string
Description
The value of rootTagAttributes will be inserted in the root tag as attributes.
Default
linkPrefix¶
Property
linkPrefix
Data type
string
Description
The value of linkPrefix will be used to precede every link generated by this plugin.
Default
tagName¶
Property
tagName
Data type
string
Description
The value of tagName defines the name of the tag that corresponds to the current level.
Default
condition¶
Property
condition
Data type
string
Description
If the condition attribute is set, the condition is evaluated and only the levels for which the condition is true, willl be used.
The condition contains a serie of fieldname/value pairs glued together with a AND or OR operator. The fieldnames and values itself are glued together with a '==' or '!=' operator. The fieldname is a fieldname from the pages table and the value is a static value.
Default
TAG object reference:
tagName¶
Property
tagName
Data type
string
Description
The value of tagName defines the name of the tag that corresponds to the current tag object.
Default
condition¶
Property
condition
Data type
string
Description
See LEVEL object reference.
Default
beforeSiblings¶
Property
beforeSiblings
Data type
boolean
Description
If the beforeSiblings attribute is set to 1, the tag is placed before the corresponding level tag, otherwise it's placed after this tag.
Default
0
ATTRIBUTE object reference:
name¶
Property
name
Data type
string
Description
Name of the attribute.
Default
value¶
Property
value
Data type
string
Description
Static value, which is used as value for the attribute. Using value will overrule any usage of field or link .
Default
field¶
Property
field
Data type
string
Description
Fieldname of the field from the pages table which value is used as value for the attribute. Using field will overrule any usage of link .
Default
link¶
Property
link
Data type
boolean
Description
If link is set to 1, a URL is constructed to the page that corresponds to the current level. Alle links are preceded by the value of linkPrefix .
Default
0
typeNum¶
Property
typeNum
Data type
integer
Description
With typeNum it is possible to add '&typeNum=...' to the generated link, if link is set to 1.
Default
ampercentNotEncoded¶
Property
ampercentNotEncoded
Data type
boolean
Description
Since the &-sign is encoded like '&' by default, but this won't work when feeding the resulted XML to, for example, a Macromedia Flash application, it is possible to keep plain &-signs in the resulted XML by setting the attribute ampercentNotEncoded to 1. This might, however, result in an error when parsing the XML through Microsoft Internet Explorer, Mozilla Firefox or any other XML parsing application.
Default
0
CDATA object reference:
value¶
Property
value
Data type
string
Description
Static value, which is used as value for the cdata. Using value will overrule any usage of field or link .
Default
field¶
Property
field
Data type
string
Description
Fieldname of the field from the pages table which value is used as value for the cdata. Using field will overrule any usage of link .
Default
link¶
Property
link
Data type
boolean
Description
If link is set to 1, a URL is constructed to the page that corresponds to the current level. Alle links are preceded by the value of linkPrefix .
Default
0
typeNum¶
Property
typeNum
Data type
integer
Description
With typeNum it is possible to add '&typeNum=...' to the generated link, if link is set to 1.
Default
ampercentNotEncoded¶
Property
ampercentNotEncoded
Data type
boolean
Description
Since the &-sign is encoded like '&' by default, but this won't work when feeding the resulted XML to, for example, a Macromedia Flash application, it is possible to keep plain &-signs in the resulted XML by setting the attribute ampercentNotEncoded to 1. This might, however, result in an error when parsing the XML through Microsoft Internet Explorer, Mozilla Firefox or any other XML parsing application.
Default
0
Known problems¶
No problems known yet.