[XML Records] How to add root node in xml generation
xml-records
Service icon
Forge component by Afonso Carvalho

Hi anyone please suggest how to add a root node in XML generation. I am generating an XML file which took values from an OS SQL out put. Also please suggest on the empty tag creation.

1. How to generate the root node <students>

2. How to generate empty tags <ID></ID> 

<students>

    <student>

         <Name>Test1</Name>

         <Email> test1@mail.com </Email> 

         <ID></ID>

    </student>

     <student> 

       <Name>Test2</Name> 

       <Email> test2@mail.com </Email> 

      <ID></ID> 

    </student> 

</students>

Champion

Hey Sreekant

Are you trying to accomplish the solution through any Extension? If not, please check if this can resolve your issue, 

Hi @manish Gupta I am using "Record list to XML" extension only. But can you tell me how to set the root node name and empty tags

mvp_badge
MVP

Hello,

I've edited your post, since I believe you're using the XML Records extension. Please let me know if I am incorrect and I will revert the changes.

You should be able to have a <students> root node if your OutSystems structure starts with a "students" list element. Can you share your module so we can take a look?

Regarding empty tags, you can use the Config structures for this:

If you name your record and specify attributes in the AttributesConfig list, you can then use the "ExcludeIfNull" flag to control if empty values are generated in the XML output.

Thank you for the answer. I have created the structure which is taking the value as an output of sql query and this pass to the record list to xml. can you suggest how to generate the empty tag like

<middle_name />

also i want the attribute and hard corded vlaue as "PUBLIC". Can suggest how to achieve this?

<record_type desc="Public">PUBLIC</record_type>


mvp_badge
MVP

I don't think the extension is prepared to handle self closing tags. <middle_name></middle_name> is possible with the ExcludeIfNull option, but I can't think of a way to generate <middle_name />.

There's no easy way to hardcode values with the Extension - if you assign the values in the Structure, it should be possible, otherwise you'd have to manipulate the XML string.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.