[XML Records] Simple example renaming not working
Question
xml-records
Service icon
Forge component by Afonso Carvalho
Application Type
Service

Hi,

I'm struggling with the xml config to rename structure properties.

I've created a very simple example :

Structure : TestingXML with 2 properties : Name and FirstName, both string

Call to RecordToXml creates : 

<TestingXML>

  <Name>Smiths</Name>

  <FirstName>Jeff</FirstName>

</TestingXML>

To rename The TestingXML tag, I add an xml config record :

With result :

<Person>

  <Name>Smiths</Name>

  <FirstName>Jeff</FirstName>

</Person>

But I can't rename the Name or FirstName tags.

If I add another XML config to the configs list, there's no difference 

Result : 

<Person>

  <Name>Smiths</Name>

  <FirstName>Jeff</FirstName>


</Person>

If I only try to rename the Name property it doesn't rename :

<TestingXML>

  <Name>Smiths</Name>

  <FirstName>Jeff</FirstName>

</TestingXML>


Can anybody help me with the renaming of properties when creating xml from record?

thx


Solution

Ok, I've found the answer.  I got confused with the 'attributes' properties.  I thought these were attributes of the XML.

This did the trick :

So for every property of the structure I want to rename, I have to add an AttributeXmlConfig

mvp_badge
MVP

Hello Nico,

This is correct. Each attribute needs a record in the AttributeXmlConfig, and they should be grouped by their parent attribute.

The RecordName of the RecordXmlConfig structure indicates the parent record, and the AttributeXmlConfig structure contains the child attributes that you want to rename.

This is why the documentation recommends that you consider string replacement if you have a lot of these operations - maintaining this structure for more than a few attributes can get unmanageable very quickly.

So, to be clear, if I want to add a namespace to every XML tag, I have to replace all opening and ending tags of the xml?  There's no way to do this faster that maybe I'm overlooking?

mvp_badge
MVP

That would be the fastest way to do it, yes. Otherwise, you would have to maintain a list of the attributes that belong to namespaces in the AttributesConfig structure. This is relatively simple if you have a few of these attributes, but if you have several namespaces/attributes, this becomes very hard to manage in the AttributesConfig structure.

I believe you can use the DefaultConfig structure if you only have one namespace and apply it to all attributes, but I have never encountered this use case.

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