[XML Records] Cannot read atributes from XML-node

[XML Records] Cannot read atributes from XML-node

  
Forge Component
(27)
Published on 2016-06-15 by Ricardo Silva
27 votes
Published on 2016-06-15 by Ricardo Silva

I'm using XmlToRecordList from component XMLRecords and try to import the xml-response from one of our suppliers to access their catalog-info in my Outsystems solution. The Soap call gives my a binary-stream which I convert to a text. This is fed to XmlToRecordList. Works very well except for one thing: the attributes of the node <Company> are not imported, leaving blank entries in the resulting import-structure. I have seen posts about this subject but was unable to translate this in a solution that works for me.


How can I import the attributes of the <Company>- node? Any help appricaiated, thanks in advance,


Rikki


<?xml version="1.0" encoding="utf-8"?>
<CatalogInfos>
<Company companyID="118" supplierID="ALAINMIKLI" name1="ALAIN MIKLI" name2="" look4opticsUrl="http://test.look4optics.de/Firma/Index.aspx?companyID=118" />
<Company companyID="75" supplierID="DE813437282" name1="AMO Germany GmbH" name2="" look4opticsUrl="http://test.look4optics.de/Firma/Index.aspx?companyID=75">
<CatalogInfo>
<CatalogName>AMO Germany GmbH</CatalogName>
<CatalogID>catalog.xml</CatalogID>
<ResourceKey>catalog.xml</ResourceKey>
<RevisionNumber>16</RevisionNumber>
<RevisionComment>Update auf Schema 1.12</RevisionComment>
<RevisionDateTime>2016-07-20T10:00:16.783</RevisionDateTime
><CatalogLanguage>de</CatalogLanguage>
<ValidCountries>
<ValidCountry>DE</ValidCountry>
</ValidCountries>
<ValidStartDate>05.04.2012</ValidStartDate>
<ProductGroups>
<ProductGroup>care</ProductGroup>
</ProductGroups>
</CatalogInfo>
</Company>
<Company companyID="79" supplierID="DE123051490" name1="Bach Optic GH-GmbH" name2="" look4opticsUrl="http://test.look4optics.de/Firma/Index.aspx?companyID=79">
<CatalogInfo>
<CatalogName>Bach Optic</CatalogName>
<CatalogID>catalog.xml</CatalogID>
<ResourceKey>catalog.xml</ResourceKey>
<RevisionNumber>434</RevisionNumber>
<RevisionComment />
<RevisionDateTime>2017-01-09T10:28:08.473</RevisionDateTime>
<CatalogLanguage>de</CatalogLanguage>
<ValidCountries>
<ValidCountry>DE</ValidCountry>
<ValidCountry>AT</ValidCountry>
<ValidCountry>CH</ValidCountry>
</ValidCountries>
<ValidStartDate>01.07.2012</ValidStartDate>
<ProductGroups>
<ProductGroup>contactlenses</ProductGroup>
<ProductGroup>care</ProductGroup>
<ProductGroup>accessory</ProductGroup>
</ProductGroups>
</CatalogInfo>
</Company>
</CatalogInfos>

Solution

Hi Rikki,

I don't know exactly what you are doing wrong but check the attached oml. That will give you the list of companies from your xml.

What I've done:

  • Created a Structure "Company" with the attributes as they appear in the xml (same name, case sensitive)
  • Created a Structure "CatalogInfos" that has an attribute Companies with type "Company List"
  • Created a variable of type "CatalogInfos List"
  • In the Action "XmlToRecordList" added your xml in the "Xml" input parameter and added "ToObject(CatalogInfos)" in "RecordList" input parameter

See if that works for you.

Cheers,

José

Solution

Hi José,

Thanks for your quick reply and solution. I tried yours and it worked flawlessly. The difference with my solution was that in my structure the first letter of an attribute was in capital (copied it from the website of the supplier), so CompanyID instead of companyID. Changed it and works perfectly now. Thanks again,

Cheers, Rikki

I'm struggling with mapping attributes from XML when the item has a direct content along with it's attributes.


In this example would be something like:

"<?xml version=""1.0"" encoding=""utf-8""?>
<CatalogInfos>
<Company companyID=""118"" supplierID=""ALAINMIKLI"" name1=""ALAIN MIKLI"" name2="""" look4opticsUrl=""http://test.look4optics.de/Firma/Index.aspx?companyID=118"">CompanyName</Company>
</CatalogInfos>"



The XML Records is putting the content ("CompanyName") on all attributes:

CatalogInfos

   Company

      companyId=CompanyName

      supplierID=CompanyName

      name1=CompanyName

      name2=CompanyName


Is there any workaround to fix this issue?