Description

The ListXMLGen can be used to load values from an XML file. For a single value, assign the Generator to that Attribute, as shown in the examples in this article. 


When needing to read values from the same XML file for different Attributes, you will need to assign this Generator to each Attribute and enter the element hierarchy for that specific value.


In This Article


Generator Parameters

The following parameters can be configured for the ListXMLGen. Items with an asterisk* are required.

  • filePath* - Defines the path where the XML file is located. 
  • fileSubDir - Defines an optional subdirectory under the filePath where the XML file exists. 
  • fileName* - Defines the name of the XML file to be opened. 
  • elementHierarchy* - Defines which element in the XML file to read data from. 
  • setLoop*- Defines whether the size of the list should be used to set the Scenario loop value. The default value is "False".
  • sortOrder* - Defines whether the list should be sorted and, if so, in ascending, descending, or random order. The default value is "noSorting".
  • seed - Defines an optional seed for randomization. Using the seed will ensure that the same random data is generated each time data is generated. 
  • list - Stores one value on each line within the list. To add values, type them in and then hit ENTER. Note that the listed value shown is only for simulation mode; when running an actual Scenario, the data will be loaded from the specified resource.



Sample XML File

<userProfiles>
  <user>
      <userId>U100346</userId>
      <fullName>Sam Thorne</fullName>
      <ssn>196-80-7949</ssn>
  </user>
   <user>
      <userId>U100347</userId>
      <fullName>Priya Nair</fullName>
      <ssn>199-45-8645</ssn>
  </user>
   <user>
      <userId>U100348</userId>
      <fullName>Mary Jones</fullName>
      <ssn>199-90-7896</ssn>
  </user>
   <user>
      <userId>U100349</userId>
      <fullName>Jim Henderson</fullName>
      <ssn>109-90-7645</ssn>
  </user>
  <user>
      <userId>U100350</userId>
      <fullName>Sherry Hunt</fullName>
      <ssn>199-91-7645</ssn>
  </user>
</userProfiles>


Example 1 - Read Full Name from File

This example will read the fullName value from the sample file above. The remaining values will be generated synthetically. A delimited file will be generated in this example. 



User Domain and Attributes

The User Domain has three Attributes: 

  • userId - Generates a patterned number value that increases by 1 for each record (e.g., 10000, 10001, 10002).
  • fullName - Reads the full name from the XML file for each record. 
  • ssn - Generates a patterned value that increases by 1 for each record (e.g., 001-01-0001, 001-01-0002, 001-01-0003).


loopCount, Receiver, and Scenario

The loopCount has been set to '1' because the number of records in the XML file determines the value. A DelimitedFileReceiver has been assigned to the Domain and a Scenario has been created. 


ListXMLGen Configuration

Values with an arrow have been changed:


Sample Output


Example 2 - Read Author ID from File

A user wants to read the author id values from an XML file and use it as part of the generated test data. A different file will be used for this example and is shown below: 


<articles>
    <article>
        <title>First steps in Java</title>
        <author id="1">
            <firstname>Siena</firstname>
            <lastname>Kerr</lastname>
        </author>
        <release-date>2018-12-01</release-date>
    </article>
    <article>
        <title>Dockerize your SpringBoot application</title>
        <author id="2">
            <firstname>Jonas</firstname>
            <lastname>Lugo</lastname>
        </author>
        <release-date>2018-12-01</release-date>
    </article>
    <article>
        <title>SpringBoot tutorial</title>
        <author id="3">
            <firstname>Daniele</firstname>
            <lastname>Ferguson</lastname>
        </author>
        <release-date>2018-06-12</release-date>
    </article>
    <article>
        <title>Java 12 insights</title>
        <author id="1">
            <firstname>Siena</firstname>
            <lastname>Kerr</lastname>
        </author>
        <release-date>2018-07-22</release-date>
    </article>
</articles>


Domain and Attributes

For this example, we have created a Writing Domain with id and authorId Attributes. 



loopCount, Receiver, and Scenario

The loopCount is '8', which means the values will repeat once since there are only four values in the XML file. A DelimitedFileReceiver has been assigned to the Domain and a Scenario has been created.



ListXMLGen Configuration

Values with an arrow have been changed:'



Sample Output


Possible Test Data Generation Errors

The following errors may be encountered when using this Generator:

1. No Element found with hierarchy <File Hierarchy> in XML for Attribute <Domain name .Attribute name>


This error occurs when the defined hierarchy within the elementHierarchy parameter is incorrect. It cannot find the element to read from the XML file. 


Example

The actual hierarchy is userProfiles.user.fullName; however, the user has entered userProfiles.user.Name. It cannot find a "Name" element. 

No Element found with hierarchy userProfiles.user.Name in XML for Attribute User.fullName

How it appears in Generator configuration:


How it appears in the XML file: 


2. Please recheck the elementHierarchy mentioned in Attribute <Domain Name. Attribute Name>

This error occurs when the value defined for the elementHierarchy parameter of the Generator configuration does not match.


Example

In this example, the hierarchy should be 'userProfiles.user.fullName'. The user receives the error because they have entered 'user.FullName'. The first element was left out; therefore, the hierarchy is invalid.

Please recheck the elementHierarchy mentioned in Attribute User.fullName


How it appears in the Generator configuration:  


How it appears in the XML file: