XML Mapping

This chapter gives a brief overview of the XML mapping by example. In general, the attributes correspond to their attribute counterparts with the difference that the parameter names are slugified as opposed to being camelCase (referring-document instead of referringDocument). See Attributes Mapping.

The following example implements all of the possible XML mapping elements:

1<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> <document name="App\Documents\ContentFolder" referenceable="true" translator="attribute" versionable="simple" is-leaf="false"> <!-- Identification --> <uuid name="uuid" /> <id name="path" /> <nodename name="name" /> <!-- Hierarchy --> <parent-document name="parent" /> <children name="children" /> <child name="block" node-name="block" /> <depth name="depth" /> <!-- Valid child classes !--> <child-class>App\Documents\Article</child-class> <child-class>App\Documents\Page</child-class> <!-- PHPCR --> <node name="phpcrNode" /> <!-- Translation --> <locale name="locale" /> <!-- Field mappings --> <field name="title" type="string" translated="true" /> <field name="resourceLocator" property="resource-locator" type="string" translated="true" /> <field name="creator" type="long" translated="true" nullable="true" /> <!-- References --> <reference-one name="anyDocumentReference"/> <reference-one name="user" target-document="Acme\Document\User"/> <reference-many name="articles" target-document="Acme\Document\Article"/> <referrers name="tags" referring-document="Acme\Document\Tag" /> <mixed-referrers name="allReferrers" /> <!-- Versioning --> <version-name name="versionName" /> <version-created name="versionCreated" /> </document> </document>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

Mapped super-classes can be mapped as follows:

1<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> <mapped-superclass name="Acme\Document\Example" referenceable="true" translator="attribute" versionable="simple"> <!-- ... --> </mapped-superclass> </doctrine-mapping>
2
3
4
5
6
7
8
9