0

I am trying to add xmlName attribute to a field in my mapping file. Now I know I can add xmlName attribute to any field by adding it manually, but I want to know if it is possible to add it using Java code.

Here is my mapping.xml file:

beanio>

  <stream name="employees" format="xml">
    <record name="employee" class="example.Employee">
      <field name="firstName" />
      <field name="lastName" />
      <field name="title" />
      <field name="salary" />
      <field name="hireDate" type="date" />
    </record>
  </stream>
  
</beanio>

In the above file, I want to set xmlName attribute for my field firstName as fName. I have looked through BeanIO documentation, but I did not see any method that would help me add xmlName attribute using Java. Is there any way to accomplish this?

Thank you for all the help.

james
  • 1
  • 1

1 Answers1

0

you can refer to BuilderApiAndAnnotations and add xmlName attribute by FieldBuilder#xmlName(String xmlName)

  • Thank you so much for answering the question, but could you please provide an example on how to implement it to read/update the file? – james Jul 22 '23 at 01:45
  • Do you mean that you want to add xmlName attribute to the mapping file by java code, why? – OpticalEngineering Jul 22 '23 at 02:51
  • I want to create data using that XML mapping file, so if I do not update that file and add xmlName attribute using java, then in the data it will have the name of that tag from code? – james Jul 22 '23 at 03:35
  • I do not want to add into it, but how do I create data using the mapping file and then use the xmlName attribute set in the code – james Jul 22 '23 at 14:48
  • I know how to create data using mapping file. I need your help because I'm going to read the same mapping file, but then for some field I will be using a different field name(xmlName) that I will define in the code. I need an example on how to set xmlName for a field inside the code. I do not want to update the mapping file, but I need to update the data that it is being created using the mapping file. – james Jul 23 '23 at 13:13