|  |  |  | License Codehaus OpenEJB OpenJMS OpenORB Tyrex

Old releases
General
Release 1.3
Release 1.3rc1
Release 1.2

Main
Home
About
Features
Download
Dependencies
Reference guide
Publications
JavaDoc
Maven 2 support
Maven 2 archetypes
DTD & Schemas
Recent HTML changes
News Archive
RSS news feed
Project Wiki

Development/Support
Mailing Lists
SVN/JIRA
Contributing
Support
Continuous builds
Prof. services

Related projects
Spring ORM support
Spring XML factories
WS frameworks

XML
XML

XML Code Generator
XML Code Generator

JDO
Introduction
First steps
Using JDO
JDO Config
Types
JDO Mapping
JDO FAQ
JDO Examples
JDO HOW-TOs
Tips & Tricks
Other Features
JDO sample JAR

Tools
Schema generator

Advanced JDO
Caching
OQL
Trans. & Locks
Design
KeyGen
Long Trans.
Nested Attrs.
Pooling Examples
LOBs
Best practice

DDL Generator
Using DDL Generator
Properties
Ant task
Type Mapping

More
The Examples
3rd Party Tools
JDO Tests
XML Tests
Configuration

About
License
User stories
Contributors
Marketplace
Status, Todo
Changelog
Library
Contact
Project Name

## How to map 'text' content

Intended Audience
Define the mapping

## Intended Audience

Any user who needs to unmarshal/marshal XML that has data represented as text as well as attributes/elements.

## Define the mapping

Consider you have XML with a structure defined as follows:

    <xml version="1.0" encoding="UTF-08"?>
    <person>
        <name>Jennifer</name>
        <age dob="21-feb-1987">21</age>
        <employment>
            <company name="unesco" />
        </employment>
    </person>

Notice the structure the element age, which has both text as well as XML markup as its content. A mapping for above XML would be as follows:

    <xml version="1.0" encoding="UTF-08"?>
    <mapping>
        <class name="abc.Person">
            <map-to xml="Person"/>
            <field name="name" type="java.lang.String">
                <bind-xml name="name" node="element"/>
            </field>
            <field name="age" type="abc.Age">
                <bind-xml name="age" node="element"/>
            </field>
            <field name="company" type="abc.Company">
                <bind-xml name="company" node="element" location="employment"/>
            </field>
        </class>

        <class name="abc.Age">
            <map-to xml="age"/>
            <field name="dob" type="java.lang.String">
                <bind-xml name="dob" node="attribute"/>
            </field>
            <field name="ageValue" type="java.lang.String">
                <bind-xml node="text"/>
            </field>
        </class>

        <class name="abc.Company">
            <field name="name" type="java.lang.String">
                <bind-xml name="name" node="attribute"/>
            </field>
        </class>
    </mapping>

Please note the different node types of the members of the `abc.Age` class, especially where the Java member `ageValue` is mapped to a node of type text.

<notice> Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved. </notice>
<notice> Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners. </notice>