Add custom attribute to field?

48 views
Skip to first unread message

Allan Larsen

unread,
Aug 24, 2017, 2:26:13 AM8/24/17
to beanio-users
I'm trying to add a custom attribute to a field, as you would to a segment.

I have added one to a segment like this:

<segment name="MySegment">
    <field name="MyAttribute" xmlType="attribute"/>
...
</segment>

That gets added just fine to the segment. But how do I add one to a field, without the attribute being added to the segment that the field belongs to?

<segment name="MySegment">
    <field name="MyField" type="string"/>
    <field name="MyAttribute" xmlType="attribute"/>
...
</segment>

I want MyAttribute to be added to MyField, and not MySegment.. is this possible?

Allan Larsen

unread,
Aug 24, 2017, 2:54:03 AM8/24/17
to beanio-users
I just figured it out myself.

Here is my solution, in case it helps someone else:

I added the field with xmlType="text", so that only the segment would be shown as an xml element.

<segment name="MyField">
    <field name="MyField" type="string" xmlType="text"/>
    <field name="MyAttribute" xmlType="attribute"/>
</segment>

This way an xml element is shown with the MyField name as it should, the attribute is added to that element, and the text from my java variable MyField, is also shown correctly:

<MyField MyAttribute="AttributeValue">VariableValue</MyField>

:)

Jimmy G

unread,
Dec 29, 2018, 10:44:37 AM12/29/18
to beanio-users
Hello Allan,

thanks a lot, it surely helped me!

Op donderdag 24 augustus 2017 08:54:03 UTC+2 schreef Allan Larsen:
Reply all
Reply to author
Forward
0 new messages