Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Not all XML child items are loaded into a class list when using XML.Reader correlate

Question
Andy Stobirski · Nov 23, 2021

Not all XML child items are loaded into a class list when using XML.Reader correlate

Hi all

I'm new to ObjectScript and I've been experimenting the correlate method of %XML.Reader to convert an XML file I've loaded into its corresponding class. But, I have found that I am not getting all the child items of an element in a List contained within the converted class, only the last item.

The XML file content is as follows:

<Results>
  <PersonIDs>
    <PersonID>1000000</PersonID>
    <PersonID>1000001</PersonID>
    <PersonID>1000005</PersonID>
  </PersonIDs> 
</Results>

I have two classes: the parent SearchResultsMessage contains a List Of the child class PersonID, as shown below. This code is simplified and has had various non-relevant bits removed.

Class GMMHTIE.ParisConnect.WebClient.Messages.Response.PersonSearchResultsMessage Extends (%Persistent, %XML.Adaptor)
{
   Property PersonIDs As list Of PersonID(XMLNAME = "PersonIDs", XMLPROJECTION = "ELEMENT"); 
}

Class PersonID Extends (%Persistent, %XML.Adaptor)
{ 
    Property PersonID As %String(XMLNAME = "PersonID", XMLPROJECTION = "ELEMENT");
}

So, when I use correlate I have a class instance for SearchResultsMessage and I can confirm that it is picking up other properties correctly (which are not shown), but the property PersonIDs only contains one item, the last 1000005.

This is the code I'm using, which is abridged for brevity:

  Set reader = ##class(%XML.Reader).%New()
  Set sc=reader.OpenString( Set reader = ##class(%XML.Reader).%New()
  Set sc=reader.OpenString(pInput)
 
  Do reader.Correlate("Results","PersonSearchResultsMessage") 
  While reader.Next(.convertedMessage,.sc) {
        // success
        w !,"Count(): "_convertedMessage.PersonIDs.Count() 
        // A value of one is returned, expecting 3
   }

Can anyone help - what am I missing?

Cheers

Andy

#ObjectScript #XML #InterSystems IRIS
Product version: IRIS 2020.1
$ZV: IRIS for Windows (x86-64) 2020.1 (Build 215U) Mon Mar 30 2020 20:14:33 EDT

Source URL:https://community.intersystems.com/post/not-all-xml-child-items-are-loaded-class-list-when-using-xmlreader-correlate